Sobes.tech
Junior — Middle

Can you list the main types of CSS selectors and explain their purpose?

sobes.tech AI

Answer from AI

Main types of CSS selectors and their purpose:

  • Type selector (e.g., div, p) — selects all elements of a given type.
  • Class selector (e.g., .button) — selects all elements with the specified class.
  • ID selector (e.g., #header) — selects the element with a specific unique id.
  • Combinator selectors:
    • Descendant selector (e.g., div p) — selects all <p> elements inside <div>.
    • Child selector (e.g., ul > li) — selects only direct children.
  • Attribute selector (e.g., [type="text"]) — selects elements with a specific attribute.
  • Pseudo-classes (e.g., a:hover, li:first-child) — select elements in a specific state.

These selectors allow flexible and precise application of styles to the desired elements on a page.

Can you list the main types of CSS selectors and… - sobes.tech