Divs vs. Classes

October 1st, 2008

This may not be an issue anymore, but I remember when I started out I had a hard time wrapping my brain around divs and classes. Looking back now I don’t see why I found it so confusing, because really it isn’t that hard at all. As a matter of fact divs and classes really aren’t related at all. The comparison should be between using IDs and using Classes.

Divs are basically blocks, and they can have an id or a class. Divs are used a lot. When ever you need to apply style to an area of your page, chances are you’re going to use a div.

Now I’ll quickly cover the basic differences between an ID and a class. A class is flexible, and it is something that you can use over and over on a page. If you were listing something, like real estate listings on a single page, and each listing has an image, a headline, some copy, etc. you would probably use a div for each listing, and give it a class, because that class can be repeated and reused on the page. An id though, every id must be unique. IDs can be linked to like anchors.

I know this was just a quick post, just because I wanted to get something up tonight since I just got the site up, but I’m going to come back to this soon with examples. If you have any burning questions, ask away.

Tags: , , ,

One Response to “Divs vs. Classes”

  1. Whats better? - Website Babble Webmaster Forums Says:

    October 8th, 2008 at 9:49 pm

    [...] classes a lot for main navigation, even though it could technically be an ID. This link may help. http://www.how-to-css.com/css/divs-vs-classes/ __________________ FNA Cotton, fna CSS help | cool [...]

Leave a Reply

Name:

Email (will not be published):

Website:

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>