HTML/CSS MCQs – Multiple Choice Questions and Answers – Part 51
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 <li> elements in a list, but only those whose index is a multiple of 4 (4th, 8th, 12th, etc.). Which CSS selector would you use?
A li:nth-child(4n)
B li:nth-of-type(4)
C li:nth-child(4)
D li:nth-of-type(4n)
2. You want to target all <input> elements that are of type text and have a readonly
attribute. Which CSS selector would you use?
A input[type="text"]:readonly
B input[type="text"]:disabled
C input[readonly][type="text"]
D input[type="text"]:checked
3. You want to apply a style to all <li> elements that are the first 5 elements in a list. Which CSS selector would you use?
A li:nth-child(-n+5)
B li:nth-child(5n)
C li:first-of-type(5)
D li:nth-of-type(5)
4. You want to target all <input> elements that have a data-id attribute with a value greater than 10. Which CSS selector would you use?
A input[data-id="10"]
B input[data-id^="10"]
C input[data-id|="10"]
D input[data-id]
5. You have a to-do list in a <ul>, and you want to apply a style to each <li> element immediately followed by another <li> element with the class .completed
. Which CSS selector would you use?
A li + li.completed
B li:has(+ li.completed)
C li ~ li.completed
D li.completed + li
6. You want to apply a style only to <h3> elements that are placed before the last <p> element in a container. Which CSS selector would you use?
A h3 ~ p:last-of-type
B h3:nth-last-child(n)
C h3:nth-child(-n+last-of-type)
D h3 ~ p:first-child
7. On a form page, you want to apply a style to all <input> fields except those with the type="password"
attribute. Which CSS selector would you use?
A input:not(type="password")
B input:not([type="password"])
C input:not(password)
D input:not([type="password"]) :focus
8. On a web page, you have several <div> elements that both have the class .box
and the attribute data-active="true"
. Which CSS selector would you use to target these elements?
A .box[data-active="true"]
B .box[active="true"]
C div.box[data-active="true"]
D .box[data-active="false"]
9. You want to apply a style only to <span> elements that contain the text “Urgent”. Which CSS selector would you use?
A span:contains("Urgent")
B span[innerHTML="Urgent"]
C span:has("Urgent")
D span:contains("Urgent")
10. You want to apply a style to all <a> elements except those with the class .disabled
. Which CSS selector would you use?
A a:not(:disabled)
B a.disabled
C a:not(.disabled)
D a:not[.disabled]