Go Back

CSS Section 2

Selectors

Selectors are used to target HTML elements and apply the same CSS properties to them.

There are several types of selectors:

If you want to apply a property to all elements, you can use the universal selector: *

Pseudo-Classes

Pseudo-classes are keywords added to selectors that define a special state of an element.

Syntax: selector:pseudoclass { property: value; }

Read the MDN documentation for more pseudo-classes.

Pseudo-Elements

Pseudo-elements allow you to style specific parts of elements.

Syntax: selector::pseudo-element

Examples include ::before, ::after, ::first-line, and ::first-letter.

Read MDN for more details.

If you add !important to a CSS property, it will override all other rules regardless of order.

CSS Inheritance

Some CSS properties (like color and font-family) are inherited by child elements from their parent.

Next: Section 6