Professional Documents
Culture Documents
5.3 CSS Selectors
5.3 CSS Selectors
CSS selector
h1 {
color: blue;
}
CSS selectors are the part that selects the HTML in order to
apply whichever rules go in between the {}.
The example above is called a Element selector.
The element selector selects all the elements that have the same
name (all h1).
Class selector
.red-heading {
color:red;
}
A class is something that we can add as an “attribute”to an
element.
A class selector can be used to multiple element so that the
same rule will be applied.
Id selector
#main {
color:blue;
}
Id vs Class selector
Class selector can be applied to many elements.
Id selector should only be applied to one element in a single HTML
file.
Attribute selector
p[draggable] {
color:red;
}
Universal selector
*{
color: red;
}