HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 50
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. You want to target all <p> elements that are descendants of an element with the class .container
. Which CSS selector would you use?
A .container > p
B .container p
C .container :p
D p .container
2. You want to target all <input> elements of type text (type="text"
). Which CSS selector would you use?
A input[type="text"]
B input:text
C input[type=text]
D input:text(type="text")
3. You want to apply a style to all <button> elements that are currently active (when a user clicks and holds them). Which CSS selector would you use?
A button:focus
B button:active
C button:enabled
D button:checked
4. You want to apply a style to all <ul> elements that contain at least one <li> element with the class .active
. Which CSS selector would you use?
A ul > li.active
B ul:has(li.active)
C ul:has(.active)
D ul li.active
5. Imagine a page with multiple information cards in the form of <div> blocks. Some cards have a red background, others a green background. You want to apply a style only to the cards with a red background. Which CSS selector would you use?
A div[style="background-color:red"]
B div[background-color="red"]
C div:has(background-color:red)
D There is no CSS selector to target elements by their background color
6. On a page, you have several sections and you want to target all sections after the third in a list of sections. Which CSS selector would you use?
A section:nth-child(3n+1)
B section:nth-of-type(n+3)
C section:nth-child(4n)
D section:nth-of-type(4n)
7. You want to apply a style to all <div> elements that have a child <h2>, but only if that child <h2> contains a specific text. Which CSS selector would you use?
A div:has(h2:contains("Text"))
B div h2:contains("Text")
C div:has(h2)
D div > h2:contains("Text")
8. You want to target all <p> elements that are non-direct children of a <section> element. Which CSS selector would you use?
A section > p
B section p
C section + p
D section ~ p
9. You have multiple buttons with the class .btn and you want to apply a style only to buttons that are currently being hovered. Which CSS selector would you use?
A .btn:hover
B .btn:focus
C .btn:active
D .btn:checked
10. You want to target all elements of a certain class but exclude the ones that are children of a specific element. Which CSS selector would you use?
A .class:not(.parent .class)
B .parent > .class
C .class:except(.parent .class)
D .class:not(.parent .class)