Basic CSS Selectors
Get an understanding of three types of CSS selectors: type, class, and ID selector.
We'll cover the following...
Basic three CSS selectors
CSS rules can select for elements in many different ways. The three basic kinds of selectors are:
typeselectors: It is used to select HTML elements by element name.classselectors: It is used to select HTML elements by a specificclassvalue.idselectors: It is used to select an HTML element associated with a specificidvalue.
The type selector
Using a type selector is as simple as typing the name of the element:
The class selector
Using a class selector is done by placing a . followed by the name of the class value:
The id selector
Using an id selector is done by placing a # followed by the id value:
Let’s take another look at type, class, and id selectors in action to see how CSS rules are applied:
Pause and think: How does the cascade decide which properties to apply to which elements?
Test your understanding
Q
Given the following HTML:
<h1 class="title">Cryptocurrency: A Brief Overview</h1>
And the following CSS:
.title {
color: blue;
}
h1 {
color: green;
}
What color will the h1 element be?
A)
Green
B)
Blue