Advanced CSS Selectors Quiz

Create an account and save your quiz results

Login and save your results

OR

Question 1/15

How would you target all
li
elements that are a direct child of a
nav
element?

Select your answer

Question 2/15

What selector could you use to select any
h1
element that has an
id
starting with 'title-'?

Select your answer

Question 3/15

How can you use CSS to select any element with a class that ends in
-highlight
?

Select your answer

Question 4/15

Which selector would correctly style only the last child
li
of every
ul
?

Select your answer

Question 5/15

Consider an application requirement to select elements that are not a
span
. What's the correct selector?

Select your answer

Question 6/15

What selector would apply a style to a
button
with an
aria-label
attribute containing the substring 'close'?

Select your answer

Question 7/15

Identify the correct selector to target all
span
elements that are siblings of any
h1
:

Select your answer

Question 8/15

How can you target the third
li
element within a
ul
using CSS?

Select your answer

Question 9/15

What would be the proper CSS selector to target an
input
element only if it's currently focused?

Select your answer

Question 10/15

For styling purposes, assume you want to select an
input
with both
type="radio"
and a specific class name 'option'. What selector would you use?

Select your answer

Question 11/15

If you need to style all elements with a
data-role
attribute, which of the following selectors should be applied?

Select your answer

Question 12/15

When attempting to select every
a
element that is the only child of its parent using CSS, which selector is correct?

Select your answer

Question 13/15

Consider a scenario where you want to select all
div
elements that have both
class1
and
class2
. Which of the following selectors should be used?

Select your answer

Question 14/15

Which selector is best to apply a style to the empty
td
elements in an HTML table?

Select your answer

Question 15/15

Which selector would you use to apply styles to an
a
element only if it has a specific attribute
href
?

Select your answer

Your Results

You did not answer any questions correctly.

Your Answers

Question 1/15
😊 Your answer was correct 🙁 Your answer was incorrect
How would you target all <pre><code>li</code></pre> elements that are a direct child of a <pre><code>nav</code></pre> element?

Available answers

The direct child selector
nav > li
selects
li
elements that are immediate children of a
nav
.
Question 2/15
😊 Your answer was correct 🙁 Your answer was incorrect
What selector could you use to select any <pre><code>h1</code></pre> element that has an <pre><code>id</code></pre> starting with 'title-'?

Available answers

The attribute selector
h1[id^="title-"]
selects any
h1
where the
id
begins with 'title-'.
Question 3/15
😊 Your answer was correct 🙁 Your answer was incorrect
How can you use CSS to select any element with a class that ends in <pre><code>-highlight</code></pre>?

Available answers

The attribute selector
[class$="-highlight"]
matches classes ending with
-highlight
.
Question 4/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which selector would correctly style only the last child <pre><code>li</code></pre> of every <pre><code>ul</code></pre>?

Available answers

Both
ul li:last-child
and
ul > li:last-child
are correct because they address the last child
li
of
ul
, regardless of its type.
Question 5/15
😊 Your answer was correct 🙁 Your answer was incorrect
Consider an application requirement to select elements that are not a <pre><code>span</code></pre>. What's the correct selector?

Available answers

The negation pseudo-class
:not(span)
selects all elements that are not
span
elements.
Question 6/15
😊 Your answer was correct 🙁 Your answer was incorrect
What selector would apply a style to a <pre><code>button</code></pre> with an <pre><code>aria-label</code></pre> attribute containing the substring 'close'?

Available answers

button[aria-label*="close"]
selects
button
elements whose
aria-label
contains 'close'.
Question 7/15
😊 Your answer was correct 🙁 Your answer was incorrect
Identify the correct selector to target all <pre><code>span</code></pre> elements that are siblings of any <pre><code>h1</code></pre>:

Available answers

The selector
h1 + span
selects only the first
span
sibling following each
h1
.
Question 8/15
😊 Your answer was correct 🙁 Your answer was incorrect
How can you target the third <pre><code>li</code></pre> element within a <pre><code>ul</code></pre> using CSS?

Available answers

The selector
ul li:nth-child(3)
selects the third
li
element within any
ul
element.
Question 9/15
😊 Your answer was correct 🙁 Your answer was incorrect
What would be the proper CSS selector to target an <pre><code>input</code></pre> element only if it's currently focused?

Available answers

The pseudo-class
:focus
is used to apply styles when the
input
element is focused.
Question 10/15
😊 Your answer was correct 🙁 Your answer was incorrect
For styling purposes, assume you want to select an <pre><code>input</code></pre> with both <pre><code>type="radio"</code></pre> and a specific class name 'option'. What selector would you use?

Available answers

Both
input[type="radio"].option
and
input.option[type="radio"]
correctly select the desired
input
elements.
Question 11/15
😊 Your answer was correct 🙁 Your answer was incorrect
If you need to style all elements with a <pre><code>data-role</code></pre> attribute, which of the following selectors should be applied?

Available answers

The attribute selector
[data-role]
selects all elements that possess a
data-role
attribute.
Question 12/15
😊 Your answer was correct 🙁 Your answer was incorrect
When attempting to select every <pre><code>a</code></pre> element that is the only child of its parent using CSS, which selector is correct?

Available answers

The
a:only-child
selector selects
a
elements that are the sole children of their parent.
Question 13/15
😊 Your answer was correct 🙁 Your answer was incorrect
Consider a scenario where you want to select all <pre><code>div</code></pre> elements that have both <pre><code>class1</code></pre> and <pre><code>class2</code></pre>. Which of the following selectors should be used?

Available answers

The selector
div.class1.class2
targets
div
elements with both classes
class1
and
class2
.
Question 14/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which selector is best to apply a style to the empty <pre><code>td</code></pre> elements in an HTML table?

Available answers

td:empty
selects
td
elements that contain no children (including text, whitespace, etc.).
Question 15/15
😊 Your answer was correct 🙁 Your answer was incorrect
Which selector would you use to apply styles to an <pre><code>a</code></pre> element only if it has a specific attribute <pre><code>href</code></pre>?

Available answers

The attribute selector
a[href]
selects
a
elements with an
href
attribute.