id vs. class

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

what is the difference? Can you use them interchangeabley? (I'm sure that is spelled wrong)

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

woman is a class, Suzanne is an id.

.woman (class="woman") has a set of characteristics.
#suzanne has a unique to her set of characteristics.

In the code, you would say:

and this would mean that this particular div of the class woman (with the same characteristics of all the other tags of class woman) is called Suzanne (suzanne is a woman), and has particular characteristics (usually visibility, positioning, et cetera) as well as shared characteristics. So the div called "suzanne" would be positioned 38 px from the top and 700 px from the left and would be on top, and absolutely so, and it would also *look* like all the other divs of the class woman, so any text would be whatever I wrote in the CSS.

Clear as mud!

Smiling Suzanne

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I know how to use them... with the "." and "#" and how to use them in tags.

But I've also had several tags share an id and had one tag use a class. That's why I ask if their interchangable.

Also, does one support functions the other doesn't? (like span and div do)

Mark Hensler
If there is no answer on Google, then there is no question.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Max,

Interchangeable? Not really (although IE may let you since it lets you use all sorts of 'shortcuts').

Hi classy woman: love that tutorial -- borders on elegance with its brevity and use of real world examples. Smiling

Vinny

Where the world once stood
the blades of grass cut me still

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.