On Tue, 29 Nov 2005, Mark Fredrickson wrote:

> Here's a general question about CSS that I've been able to quite figure
> out. If one has a DIV that will only appear once per page, which should
> one use: a class or an id?

An oldie, but a goodie (beware obsolete code):

http://www.hotwired.com/webmonkey/templates/print_template.htmlt?meta=/webmonkey/98/05/index3a_meta.html

Is a reflection on how one might decide to choose which attribute to 
assign.

> Classes are obviously useful at applying to multiple elements, or
> applying multiple classes to one element. What advantages have that
> classes do not? Specificity comes to mind, but the CSS rules regarding
> this are hazy in my mind and I do not know if ids provide more
> specificity than classes.

ID's are in fact more specific than classes; the spec discusses a scheme 
involving a combination of logarithmic and arithmetic weighting.

If you are nearly or entirely certain that you will only need to use a 
given component of a selector within a given page, then there's no reason 
why you shouldn't put it in an id context.  Also, id is easier to work 
with when scripting, as a rule.  With id's you merely need to check for 
the existence of an id in one line; with classnames you need to walk 
through all or part of the document tree, checking each node as you go 
along.


--
Ben Henick                "In the long run, men hit only what they aim
Sitebuilder At-Large       at.  Therefore, though they should fail
http://www.henick.net/     immediately, they had better aim high."
[EMAIL PROTECTED]       -- Henry David Thoreau

______________________________________________________________________
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to