Using Classes And Ids.

April 19, 2008 by Cherise
Basics of Classes and ID’s

Classes and ids are using to style parts of layouts. You can put a class or id in to a div or table and with your style sheet it’ll style it for you. You have to give them names though this is helpful you can use mutipale class and id names to style you’re website.

So in a style sheet a class would look like this
.NAME {
Background-color:#000000;
}

.NAME is the name of your class. Note the period at the start of the coding. That means it’s a class.

And this is what an ID would look like in a style sheet.
#NAME {
Background-color:#000000;
}

#NAME is the name of your class. Note the number sign at the start of the coding. That means it’s a ID.

Now they look so much alike but what’s different about them? Well ID’s are only supposed to be used once through out your webpage. So say you have an ID named NAME2 and another ID named NAME3 each should only be used once in the HTML page. ID’s can be used more than once in CSS but they should have different names of course.

Classes can be used mutable times through out a page. Say you have a blog and each post has a div wrapper you would use a class for this type of thing,

Using Classes And ID’s in Divs Or Tables

All you need to do to add a class or id style to a div or table is put class=“NAME” or id=“NAME” right after the word div or table. Like…

<div class=“NAMV”>Content</div> or <div id=“NAMVE”>Content</div>

<table class=“”NAME“>Content</div> or <table id=“”NAME“>Content</div>