HTML/CSS MCQ

HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 57

Multiple choice questions and answers (MCQs) on HTML/CSS to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as tags, web standards, CSS selector, objects, and more. This quiz will easily prepare anyone to pass their online test.
 
 

1. Which CSS selector targets all <p> elements inside a <section> container, but not those inside a <div>?

A section p:not(div p) {}

B section > p:not(div p) {}

C section p:not(div p) {}

D section > p {}

A
The selector section p:not(div p) targets all <p> elements inside a <section> but excludes those inside a <div>. This allows selecting only the paragraphs within a <section>, not in a <div>.
 

2. Which CSS selector targets all <a> elements on a page, except those inside a navigation menu with the class nav?

A a.nav a {}

B a:not(.nav a) {}

C a:not(.nav) {}

D a:not(.nav a) {}

B
The selector a:not(.nav a) targets all <a> elements except those inside an element with the .nav class. This allows styling all links except those in a specific navigation menu.
 

3. Which CSS selector targets all <div> elements with the class highlight that contain an <img> element with an empty alt attribute?

A .highlight img[alt=""] {}

B .highlight img:empty[alt=""] {}

C .highlight img[alt=""]:not(:empty) {}

D .highlight img[alt=""] {}

A
The selector .highlight img[alt=""] targets all <img> elements inside <div> elements with the class highlight, where the alt attribute is empty. The alt="" filters these specific images.
 
 

4. Which CSS selector targets a <div> element with the class wrapper that contains more than 5 <p> elements?

A div.wrapper:has(p:nth-child(n+5)) {}

B div.wrapper > p:nth-child(n+5) {}

C div.wrapper p:nth-child(n+5) {}

D div.wrapper:has(p) {}

A
Although the :has() pseudo-class is not yet fully supported in all browsers, it theoretically allows targeting a <div> with the class wrapper that contains more than 5 <p> elements. The selector p:nth-child(n+5) selects any <p> that is the fifth child or beyond.
 

5. Which CSS selector targets all <input> elements of type text that have a placeholder attribute starting with “Enter”?

A input[type="text"][placeholder^="Enter"] {}

B input[type="text"]:placeholder^="Enter" {}

C input[type="text"]:placeholder-start("Enter") {}

D input[type="text"]::placeholder^="Enter" {}

A
The selector input[type="text"][placeholder^="Enter"] targets all <input> elements of type text whose placeholder attribute starts with the string “Enter”. The ^ means “starts with”.
 

6. Which CSS selector targets all <p> elements on a page except those inside a <section> with the class no-style?

A section.no-style p {}

B p:not(.no-style p) {}

C p:not(section.no-style p) {}

D p:not(section > .no-style) {}

C
The selector p:not(section.no-style p) targets all <p> elements except those inside a section with the class no-style. The :not() excludes elements that match the given condition.
 
 

7. Which CSS selector targets all <input> elements of type radio with a name attribute equal to “gender” that are checked?

A input[type="radio"][name="gender"]:checked {}

B input[type="radio"]:checked[name="gender"] {}

C input[name="gender"]:checked {}

D input[type="radio"][name="gender"]:active {}

A
The selector input[type="radio"][name="gender"]:checked targets all radio <input> elements with the name attribute “gender” that are checked. The :checked pseudo-class is used to select checked elements.
 

8. Which CSS selector targets all <span> elements that are directly followed by a <div> element in a section with the class content?

A section.content span + div {}

B section.content > span + div {}

C section.content span + div {}

D section.content span > div {}

C
The selector section.content span + div targets all <div> elements immediately following a <span> in a section with the class content. The + indicates a direct sibling relationship.
 

9. Which CSS selector targets all <a> elements in a navigation menu (nav) that have not been visited yet?

A nav a:visited {}

B nav a:link {}

C nav a:unvisited {}

D nav a:active {}

B
The selector nav a:link targets all unvisited links in a <nav> element. The :link pseudo-selector selects links that haven’t been visited yet.
 
 

10. Which CSS selector targets all <p> elements in a .blog container that are not followed by a <ul> element?

A .blog p:not(+ ul) {}

B .blog p:not(:has(+ ul)) {}

C .blog p:not(:has(ul)) {}

D .blog p + :not(ul) {}

C
The selector .blog p:not(:has(ul)) targets all <p> elements in a .blog container that are not followed by a <ul>. The :has() pseudo-selector allows filtering out those that are followed by a <ul>.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *