Forum Moderators: open

Message Too Old, No Replies

Curiousity Question?

When to use ID vs Class in <div>

         

sparrow

1:26 pm on Jul 31, 2002 (gmt 0)

10+ Year Member



I've seen instance of both used, and I am seeing more and more <div> tags us class instead of ID. Is there any true revelance left to the
ID?

rewboss

1:43 pm on Jul 31, 2002 (gmt 0)

10+ Year Member



Yes. An ID is used to reference a unique element. This may be crucial in DHTML applications, for example.

papabaer

3:34 pm on Jul 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ID's can also provide a blueprint to a page aid in construction, and serve as mnenomics: since their tend to be fewer ids usedm and since only one occurance per page is allowed, it is easy to recall what well named ids are used for.

#banner-top {some styles}
#nav-left {some styles}
#main-menu {some styles}

And so on....

Also, since you ARE using an ID, you can target with an url to provide navigation AND styling all in one shot!

<a href="#main-menu">Go to Main Menu: Guess what? I got style too!</a>

[edited by: papabaer at 3:39 pm (utc) on July 31, 2002]

sparrow

3:39 pm on Jul 31, 2002 (gmt 0)

10+ Year Member



papbaer, you spawned my question, becuase I was reading another thread you had attended and answered and say that you used the "class" instead of the "id", where I thought you would had used the "id".

It still a little confusing to me, for the most part I have used "class" but I was now experimenting with "id"

papabaer

3:44 pm on Jul 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sparrow, that was in refernce to applying multiple classes to an element. I do style ids, but I use them as intended and only assign ids where warranted.

Think of it as currency: classes are the smaller denomination, the "loose change" if you will. Id's on the other hand represent serious "folding money" - they should be used for key elements.

papabaer

3:50 pm on Jul 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remember, you can assign key styles to your unique id's and then "tweak" them by using your various .classes:

<div id="main-menu" class="red">Id with class!</div>

- papabaer

sparrow

4:17 pm on Jul 31, 2002 (gmt 0)

10+ Year Member



I think I got it now papabaer. I am going to try it out, (well, when
time permits), I am still struggle with a WebMail client that will work the way we want. But in between work on this I am going to try it.

By the way I stopped at your site today, and was checking out your CSS page, how long before you'll get so additional info on it. I find your input and explanations extremely helpful.