QuizzesSelectors and Pseudo-Classes — Concept Check
intermediate
html-css

Selectors and Pseudo-Classes — Concept Check

Questions on Selectors and Pseudo-Classes. Beyond classes there is a whole vocabulary — combinators, structural pseudo-classes, :has() — that removes the need for extra markup and JavaScript.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Selectors and Pseudo-Classes — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer wants to apply styles to all direct children of a container with the class 'stack', except the first child. Which CSS selector should they use?

    • A.stack > :not(:first-child)
    • B.stack > *:first-child
    • Cli:first-child
    • D.stack > * + *
  2. 2.You notice a button remains styled as if it is focused even after clicking elsewhere on a mobile device. What could be the reason?

    • AThe button uses :focus, which is not cleared on mobile.
    • BThe button uses :focus-visible, which doesn't trigger on touch devices.
    • CThe button uses :active, which remains after interaction.
    • DThe button uses :hover, which persists on mobile devices.
  3. 3.A form input should only show a red border when it is invalid and the user has interacted with it. Which selector achieves this?

    • Ainput:required:invalid
    • Binput:user-invalid
    • Cinput:invalid
    • Dinput:placeholder-shown
  4. 4.A developer uses the selector 'body:has(dialog[open])'. What is the purpose of this selector?

    • ATo style dialogs within the body.
    • BTo check if the body contains any open elements.
    • CTo style open dialogs only.
    • DTo style the body when any dialog is open.
  5. 5.A list is styled with 'li:nth-child(odd)'. What effect does this have?

    • AStyles every odd-numbered list item.
    • BStyles every even-numbered list item.
    • CStyles only the first list item.
    • DStyles the last list item.
  6. 6.Which pseudo-class would you use to style a container when any of its children have focus?

    • A:focus-within
    • B:hover
    • C:focus
    • D:focus-visible
  7. 7.A developer wants to style links that have been visited. Which pseudo-class should they use?

    • A:active
    • B:checked
    • C:hover
    • D:visited
  8. 8.What does the selector 'a[href^="http"]' target?

    • ALinks with href ending with 'http'.
    • BLinks with href exactly 'http'.
    • CLinks with href containing 'http'.
    • DLinks with href starting with 'http'.