HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 52
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 apply a style to <input> elements that have a data-index
attribute with a numeric value less than 5. Which CSS selector would you use?
A input[data-index<5]
B input[data-index="5"]
C input[data-index]
D input[data-index=""]
2. You want to target all <section> elements that have exactly 3 child elements. Which CSS selector would you use?
A section:nth-child(3)
B section:has(> *:nth-child(3))
C section:only-child
D section:nth-of-type(3)
3. You want to apply a style to all <div> elements that contain at least one <p> element with the class .highlighted
. Which CSS selector would you use?
A div > p.highlighted
B div + p.highlighted
C div > .highlighted
D div:has(p.highlighted)
4. You want to apply a style only to <input> elements that are of type "checkbox" and are checked. Which CSS selector would you use?
A input[type="checkbox"]:checked
B input[type="checkbox"]:focus
C input:checked[type="checkbox"]
D input:checked:not([type="checkbox"])
5. You want to apply a style to all <p> elements that immediately follow an <h2> element in a container, but only if that <h2> element contains specific text. Which CSS selector would you use?
A h2 + p:contains("text")
B h2:has(+ p):contains("text")
C h2 + p:has(:contains("text"))
D h2 + p
6. You want to apply a style to all <input> elements of type radio that have the disabled
attribute. Which CSS selector would you use?
A input[type="radio"]:disabled
B input[disabled][type="radio"]
C input[type="radio"]:checked:disabled
D input[disabled]:radio
7. You want to apply a style to all <p> elements that are not preceded by an <h1> element. Which CSS selector would you use?
A p:not(h1 ~ p)
B p:not(:has(h1))
C p:not(:preceded-by(h1))
D p:not(h1 + p)
8. You want to apply a style to all <div> elements that have a <p> child in the fourth position among their children. Which CSS selector would you use?
A div p:nth-child(4)
B div:nth-child(4) p
C div > p:nth-child(4)
D div p:nth-of-type(4)
9. You want to apply a style to all visited <a> links, but only if their text color is red. Which CSS selector would you use?
A a:visited { color: red; }
B a:visited:color(red)
C a:visited { color: red; }
D a:visited:not(:color(red))
10. You want to apply a style to all <div> elements that contain a <p> element that is currently being hovered. Which CSS selector would you use?
A div:hover p
B div:has(p:hover)
C div > p:hover
D div p:focus