CSS: Group Common Styles into Shared Classes
You can group styles common to different rules into their own classes to save repeating yourself. CSS2-compliant browsers can reference multiple classes within individual elements. For example: This ability to reference multiple classes gives authors newfound options when styling their content. For elements that share the same styles ( Becomes this after grouping the common center style into one shared class: The third This technique of grouping common styles within shared classes is supported by most modern browsers. You can combine shared classes with grouping of selectors and declarations and shorthand properties to create optimized CSS rules.<div id="nav" class="nav center">...</div>text-align:center for example), you can group these shared styles into one shared class. So this:<style type="text/css">
<!--
.nav{color:red; text-align:center;}
.main{color:#000; text-align:center;}
-->
</style>
...
<div id="nav" class="nav">...</div>
<div id="main" class="main">...</div><style type="text/css">
<!--
.nav{color:red;}
.main{color:#000;}
.ctr{text-align:center;}
-->
</style>
...
<div id="nav" class="nav ctr">...</div>
<div id="main" class="main ctr">...</div>.ctr class groups the common styles (in this case the center declaration) into a class now shared by two elements. The additional class saves space by eliminating redundant common declarations, which can add up for larger style sheets. In effect, you are normalizing your CSS.Further Reading
font and border in CSS to shrink your style sheets.
By website optimization on 12 Jan 2004 AM
Comments
Hello Sir,
I want this site in center without table
can you explain how I can do a center in div style?
Regards
Vinay
By: Solanki Vinay on April 23, 2007 1:16 AM
