First page Back Continue Last page Graphics
Classes and IDs: Classes
HTML has two attributes that make CSS even more useful: class and ID. They make it easy to apply style to just about any tag.
Classes can describe a generic style that can be applied to any HTML element, or can be created for specific elements.
When defining a style for elements with a particular class attribute in the Style Sheet, declare a rule using a dot (.) followed by the class name. To limit the style to a particular element with that class attribute, use a selector combining the tag name with a dot followed immediately by the class name.
- The following rule would apply to any element with the attribute class=“shade"
- .shade { background: yellow; }
- The following rule would apply only to paragraph tags with the class shade (<p class="shade">)
- p.shade { background: red; }