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.
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.
Division class="right"
The HTML/CSS
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
}
Example
div.right { width:49%; float:right; margin: 0 0 0 0; padding: 0 0 ; border: none }
Example of Image Nested in Right Division
The HTML
To define the properties of an image inside div.right:
<div class="right">
<img src="image url" alt="alt text" >
</div>
The CSS
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
}
Be More Specific
You should define specific classes for your images and most page elements:
👉See: Rule #2 Images and Aligning Images
More Examples
Element | HTML | CSS |
---|---|---|
paragraph | <p> | p {font-size:20px; padding :1% 5%} |
p centered | <p class="center"> | p.center {text-align:center} |
h3 heading | <h3> | h3 {font-size: 20px; text-align:center} |
h3 left | <h3 class="left"> | h3.left {text-align:left} |
ul list | <ul class="special"> | ul.special {list-style:none; color: #0066cc} |
span | <span class="slogan"> | .slogan {font-style:oblique;} |
Free Tools and Resources
Free Bullet Images, WingDings and WebDings
🔵 🔶 😀 🎈 🐝 🏀 👉 👲 💡 🍅
Have you tried our NEWEST template kit with scrolling columns? Download Template Kit #601 - 4 Page Kit or Test Drive It!