Selecting Elements
Explore the fundamentals of CSS selectors and how to target HTML elements effectively. Learn to use element, class, id, and universal selectors to style your web page with precision and improve readability by combining selectors.
We'll cover the following...
We'll cover the following...
We use selectors to target the HTML elements we want to style with CSS. We do this by associating declarations to elements on the web page.
The four basic selectors are:
- Element
- Class
- ID
- Universal
Element selectors
We use an element selector to select an HTML element by its name. For example, we have a paragraph of text on our HTML page, given below:
<p>My paragraph</p>
Using CSS, we can select this p element and style it however we like. For example, we may want to change the color of the text to red.
We ...