Pseudo-classes
Pseudo-classes allow you to select specific states or positions of an element. For example, :hover
selects the element when the mouse pointer is over it, :focus
selects the element when it is selected or has focus, :nth-child()
selects a specific child element in a group.
Examples:
Pseudo-elements
Pseudo-elements allow you to create virtual elements to customize an existing element.
For example, ::before
and ::after
create elements before and after an element, ::first-line
and ::first-letter
select the first line and first letter of an element.
Examples:
Combinators
Combinators allow you to combine selectors to select elements based on their relationship. For example, element1 element2
selects element2
inside element1
, element1 > element2
selects direct child elements of element1
, element1 + element2
selects element2
immediately after element1
.
Examples:
Attribute selectors
Attribute selectors allow you to select elements based on the value of their attributes. For example, [attribute]
selects elements with the attribute attribute
, [attribute=value]
selects elements with the attribute attribute
equal to value
, [attribute^=value]
selects elements with the attribute attribute
starting with value
.
Examples:
:not()
selector
The :not()
selector allows you to select elements that do not match a specific selector. For example, :not(.class)
selects elements that do not have the class class
, :not(#id)
selects elements that do not have the ID id
.
Examples:
These examples demonstrate advanced element selection in CSS. You can customize and apply these techniques to style and customize elements on your web page as desired.