HTML and CSS Reference
In-Depth Information
Reusing Styles
In the old days, we wrapped font tags and applied background attributes
to every HTML element that needed styling. This was, of course, very
impractical, and thus CSS was born. CSS enabled us to reuse styles from
one part of the page on another.
For example, a navigation menu has a list of items that all look the same.
Repeating inline styles on each item wouldn't be practical. As a result, we
begin to see CSS like this:
#nav {
margin: 0;
padding: 0;
list-style: none;
}
#nav li {
float: left;
}
#nav li a {
display: block;
padding: 5px 10px;
background-color: blue;
}
Sure beats adding float:left to every list item and display:block; padding:5px
10px; to every link. E ! ciency, for the win! Just looking at this, you can see
the HTML structure that is expected:
<ul id="nav">
<li><a href="/">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/contact">Contact Us</a></li>
</ul>
Search WWH ::




Custom Search