Selectors and Declarations
CSS selectors and declarations are the backbone of styling web pages. Selectors target HTML elements, and declarations define the style rules. Let's explore how to use them.
1. Selectors:
CSS selectors determine which elements on the HTML page your styles will apply to. Here are some common types:
Element Selector:
Class Selector:
ID Selector:
Attribute Selector:
Combining Selectors:
2. Declarations:
Once you've selected an element, you define the style rules with declarations inside curly braces {}. Each declaration consists of a property and a value.
Property: Describes the aspect of the selected element you want to style (e.g., color, font-size, margin).
Value: Specifies the style for the chosen property (e.g., #333 for color, 16px for font size).
3. Combining Selectors and Declarations:
By combining selectors and declarations, you can precisely target HTML elements and define their styles.