0
0
CSSmarkup~20 mins

Complex selector combinations in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
Which selector matches all
  • elements that are direct children of
      but not those inside nested
        ?
  • Consider the following HTML structure:
    <ul>
      <li>Item 1</li>
      <li>Item 2
        <ul>
          <li>Subitem 2.1</li>
        </ul>
      </li>
      <li>Item 3</li>
    </ul>

    Which CSS selector will style only the top-level <li> elements?
    Aul > li
    Bul li
    Cul li > ul li
    Dul + li
    Attempts:
    2 left
    💡 Hint
    Think about the difference between direct child and any descendant selectors.
    selector
    intermediate
    2:00remaining
    Which selector matches all elements that are both checked and disabled?
    You want to style all checkboxes or radio buttons that are checked and disabled at the same time.
    Which CSS selector will select these elements?
    Ainput:checked:disabled
    Binput:checked, :disabled
    Cinput[checked][disabled]
    Dinput:checked & :disabled
    Attempts:
    2 left
    💡 Hint
    Use pseudo-classes combined without commas to select elements matching all conditions.
    selector
    advanced
    2:00remaining
    What is the specificity of the selector 'section#main.content > article.highlighted:first-child'?
    Calculate the specificity of this CSS selector:
    section#main.content > article.highlighted:first-child

    Specificity is counted as (a,b,c) where:
    - a = number of ID selectors
    - b = number of class, attribute, and pseudo-class selectors
    - c = number of type selectors and pseudo-elements
    A(1,3,3)
    B(1,2,3)
    C(0,4,2)
    D(1,3,2)
    Attempts:
    2 left
    💡 Hint
    Count each selector type carefully: IDs, classes/pseudo-classes, and element names/pseudo-elements.
    layout
    advanced
    2:00remaining
    Which CSS selector combination correctly targets all
    You want to style all
    Anav button:disabled.active
    Bnav button:disabled, nav button.active
    Cnav > button:disabled, nav > button.active
    Dnav button:disabled, .active
    Attempts:
    2 left
    💡 Hint
    Remember that commas separate selectors and each selector applies independently.
    accessibility
    expert
    3:00remaining
    Which complex selector best targets all focusable elements inside a form for custom focus styling, excluding disabled elements?
    You want to apply a custom focus style to all focusable elements inside a form, but you want to exclude any elements that are disabled.
    Which CSS selector will correctly select these elements?
    Aform :focus:not(:disabled)
    Bform :focus:enabled
    Cform :is(input, select, textarea, button):not(:disabled):focus
    Dform :is(input, select, textarea, button):focus:disabled
    Attempts:
    2 left
    💡 Hint
    Use :is() to group element types and :not() to exclude disabled elements.