CSS: Use ID Selector or Classes?
March 19th, 2008 by George
When should you use an ID Selector or a class in CSS?
There are many of answers, some more technical than others, but here’s a fast and dirty answer.
Use an ID selector when it will be used only once on the page. For example, DIVs for header, body and footer are just begging to be ID selectors.
Use a Class name when an element will be used more than once on a page. As an example, if you have styles for external links and a different style for internal links you should use a Class name.
SAMPLE: What it Looks Like
<html>
<head>
head code here
</head><body>
<div id=”header”> Header stuff here </div>
<div id=”content”> Page content here including an <a href=”something.html” class=”ilink”>internal link</a> and an <a href=”http://www.somewebsite.com” class=”elink”>external link</a>. </div>
<div id=”footer”> Footer stuff here </div>
</body>
</html>
Category: Web Design | 2 Comments »