Target elements accurately without brittle markup.
- type
- class
- ID
- attribute
- combinators
- grouping
- pseudo-classes
- pseudo-elements
Style a navigation list and form using classes, attributes, and interaction states.
- Open the result in a browser and inspect the HTML and computed CSS.
- Test at narrow and wide widths and use the keyboard for interactive elements.
- Write down one thing you changed after testing.
Selectors describe which elements a rule matches. Type selectors are broad, classes are reusable, IDs identify one element, attribute selectors match data or control types, and combinators describe relationships in the tree. Pseudo-classes match states or positions; pseudo-elements address parts of a rendered element. Prefer simple classes for component styling and use relational selectors when the relationship is meaningful.
A deeply nested selector becomes fragile when HTML changes. An ID selector often creates more specificity than a reusable component needs.
Style a list with a direct-child selector, one attribute selector, and one interaction state. Move an element in the DOM and predict which rules still apply.
- Rebuild the core idea without copying the example line by line.
- Explain the key HTML or CSS choice in your own words.
- Test the result at a narrow width and with keyboard navigation where relevant.
Open example.html in a browser. Edit style.css, save, and refresh.
Try: Add a selector that targets only the first card.