CSS: Use ID Selector or Classes?
Mar, 19, 2008
Posted byWhen 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>
RELATED POSTS
- » PHP Timezone Hack - Overriding server timezone
- » Site Design Basics - Navigation and Links
- » Using .htaccess to set a custom 404 page
- » Dreamweaver 8 'Bug': This search result cannot be displayed because
- » Dreamweaver: Find Replace in Open Documents
Posted in Web Design by |