Class Selector
A type selector styles all elements of a type. Often, though, you want to style only some of them. That’s what classes are for.
A class is a label that you give to elements with the class attribute. On our page, the two div elements with the description and the physiology of the cat have the class group:
<div class="group">
<h2>Description</h2>
...
</div>You make up the name of a class yourself. It should say what the elements are, and it can’t contain spaces, so use hyphens instead: title-background. Unlike an id, a class can be shared by any number of elements, and one element can have several classes, separated by spaces: class="group highlighted".
To select the elements with a class, write a dot followed by the name of the class:
.group {
color: purple;
}Don’t forget the dot. Without it, group would be a type selector looking for <group> elements, and there are none on the page.
Instructions
- 1
Create a rule for the class
groupthat sets a light beige background:background-color: linen. - 2
In
index.html, give the classgroupalso to thedivwith the idbreeds. Thanks to the rule you’ve just written, it will get the same background.