A selector like p styles every paragraph. To style only some elements, give them a name in the HTML and use that name in the CSS.
Classes
A class is a label you can put on as many elements as you like:
<p class="warning">The floor is wet.</p>
In CSS, select a class with a dot in front of its name:
.warning {
color: red;
}
An element can have several classes, separated by spaces: class="warning big".
IDs
An id names one single element. No two elements on a page may share an id.
<p id="intro">Welcome!</p>
Select an id with a hash sign:
#intro {
font-size: 20px;
}
Which one to use?
Use classes for almost all styling, because they can be reused. Keep ids for the few things that truly exist once, and for connecting labels to form fields.
You choose the names. Pick ones that describe what the thing is (warning, price, card), not how it looks (red, big). The look may change later; the meaning will not.
Your Task
- In
index.html, add the classspecialto the two list items marked as today's specials. - In
style.css, make everything with the classspecialcrimson. - Give the paragraph at the bottom the id
note, and use an id selector to make its textgray.
- The two specials have the class
special, and the other items do not - The specials are
crimsonand the other items are not - The last paragraph has the id
note - The CSS uses the
#noteselector to make itgray