HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 53
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 all <p> elements that follow an <h1> or <h2> element, but not an <h3>. Which CSS selector would you use?
A h1 + p, h2 + p, :not(h3 + p)
B h1 + p, h2 + p, :not(h3 ~ p)
C h1 ~ p, h2 ~ p, :not(h3 + p)
D h1 + p, h2 + p
2. You want to apply a style to all <a> links with a data-role attribute equal to "admin"
. Which CSS selector would you use?
A a[data-role="admin"]
B a[data-role="admin"]:link
C a[data-role="admin"]:visited
D a[role="admin"]
3. You want to style all <input> elements of type "text"
only when they are disabled. Which CSS selector would you use?
A input[type="text"]:disabled
B input[type="text"]:not(:enabled)
C input[type="text"]:focus:disabled
D input[type="text"]:disabled:focus
4. You want to apply a style to all <p> elements that appear before the last <h2> on the page. Which CSS selector would you use?
A p:nth-child(-n+last-of-type(h2))
B p ~ h2:last-of-type
C p:not(:last-of-type) ~ h2
D p:not(h2:last-child)
5. You want to apply a style to all <a> links that are both hovered and have been visited. Which CSS selector would you use?
A a:hover:link:visited
B a:hover:visited
C a:visited:hover
D a:visited:hover:link
6. You want to apply a style to all <button> elements that do not have the disabled attribute. Which CSS selector would you use?
A button:not([disabled])
B button:not([disabled=true])
C button[disabled]:not()
D button[disabled=false]
7. You want to apply a style to all <ul> elements that contain exactly two <li> elements. Which CSS selector would you use?
A ul:has(li:nth-child(2))
B ul > li:nth-child(2)
C ul > li:nth-of-type(2)
D ul:has(> li:nth-child(2))
8. You want to apply a style to all <input> fields of type “checkbox” that are checked, but not disabled. Which CSS selector would you use?
A input[type="checkbox"]:checked:enabled
B input[type="checkbox"]:checked:not(:disabled)
C input[type="checkbox"]:enabled:checked
D input[type="checkbox"]:disabled:checked
9. You want to apply a style to all <li> elements that are in the 3rd and 5th position in a list. Which CSS selector would you use?
A li:nth-child(3), li:nth-child(5)
B li:nth-child(3n+5)
C li:nth-of-type(3), li:nth-of-type(5)
D li:nth-child(odd)
10. You want to apply a style to all <p> elements that contain the word “CSS”, regardless of case. Which CSS selector would you use?
A p:has("CSS")
B p:contains(text("CSS"))
C p:contains("CSS")
D p:has(:contains("CSS"))