3 replies [Last post]
osirius
Offline
newbie
the known universe
Last seen: 17 years 25 weeks ago
the known universe
Joined: 2004-11-26
Posts: 4
Points: 0

This is probably a n00bish question but what IS the difference? In a lot of tutorials classes are used for things like DIVs while id's are used for UL and LI etc but can someone explain why....thank you

EDIT: i've come across another problem - i've been trying to align text in a DIV box to the bottom right but it doesn't seem to work, I used the 'align' and 'valign' HTML properties but the text only aligns to the right not to the bottom, any ideas?

dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 6 years 16 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

"class" and "id" - what's the difference

There was a discussion about Class vs ID only a couple of days ago:
http://www.csscreator.com/css-forum/ftopic6490.html

It's probably worth giving the forum search function a workout, most issues have been covered before.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

thepineapplehead
thepineapplehead's picture
Offline
Moderator
Last seen: 3 weeks 4 days ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9683
Points: 819

"class" and "id" - what's the difference

In the css, replace valign (a html property) with vertical-align (a css property).

Keep in mind, vertical-align: center (or middle) won't work - do a search.

Verschwindende wrote:
  • CSS doesn't make pies

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 11 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

"class" and "id" - what's the difference

thepineapplehead wrote:
In the css, replace valign (a html property) with vertical-align (a css property).

Keep in mind, vertical-align: center (or middle) won't work - do a search.

The html attribute, valign, and the css property, vertical-align, are not equivalent.

The VALIGN attribute can be used to explicitly specify the vertical alignment of material within caption,col, colgroup, tbody, td, tfoot, th, thead, and tr. In other words, it belongs to the table elements.

The vertical-align property controls placement within the line-box according to the inline formatting model. It is more complex than I can explain. Smile

osirius wrote:
This is probably a n00bish question but what IS the difference [between "id" and "class"]? In a lot of tutorials classes are used for things like DIVs while id's are used for UL and LI etc but can someone explain why....thank you

An id is simply a name that that identifies a single element, just as "John" refers to a particular individual. A class applies to (possibly) many individuals. For example, all individuals with red hair are in the class, "redhead". Each document may have only one "John" element, but may have any number of "redhead" elements.

Both are handy for their ability to categorize elements. For example, you might have a header across the top of your page. By giving it an id, say #banner, you can create a div of that name and set property values for all elements that descend from that div, and not affect those same elements that are not descendent from #banner. You can have only one #banner.

Class is more promiscuous. You may have any number. They are handy for causing the same values to be applied at different times. You may wish to have some text appear in red, have a line-over, an outset border, and x-large font size. You can make a class, "red" with those properties, and apply it as needed throughout the document.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.