Creating Classes for HTML Elements
with the Class Attribute
The class attribute is a Global Attribute.
You can define a class for any web page element that accepts global attributes.
In HTML code it looks like this:
<div class="right"></div>
To define its properties in the style sheet it would be referenced as:
div.right {
properties here
}
Since the id attribute must be unique and only used once on a page, the class attribute is the preferred method of defining custom properties for HTML elements.
Example
To define the properties of an image inside div.right:
<div class="right">
<img src="image url" alt="alt text" >
</div>
To define its properties in the style sheet it would be referenced as:
div.right img {
margin : 10px 10px;
box-shadow: 1px 1px 4px #000
}