At 04:08 PM 6/29/2005, Jack Keller wrote:
This is a question that I am curious about, I normally layout everything with #idname but I've noticed here and there different tutorials using div.classname instead for positioning.

Both seem to work, the class system seems to work easier, can anyone explain the positives and/or negatives to either or both approaches?


Jack,

I'd say neither id nor class "works more easily" as a generic statement. Like a hammer and a screwdriver, neither is better generally, but they're each better than the other at performing specific tasks.

Ids must be unique on the page, classes need not be.

Ids are handy for pinpointing a specific item, or lassoing all the children of a specific parent. Classes are handy for describing a number of items that share certain attributes.

An element can have only one id but can have multiple classes:
        <p id="intro" class="body sidebar">
That paragraph would be affected by any of these rules:
        p#intro {}
        p.body {}
        p.sidebar {}
        p#intro.sidebar {}
        p.sidebar.body {}   <== IE will see only the last class listed

Finally, ids have a greater valence in computing CSS specificity than classes, so that in this instance:

        p#intro   { color: #F00; }
        p.sidebar { color: #00F; }

The id rule will override the class rule, even though it comes first, because ids "weigh" more than classes.

You should definitely read the CSS 2.1 specification entirely, but focusing on:
http://www.w3.org/TR/CSS21/selector.html

If you google +css +classes +ids you'll come up with tons of explanations, such as:
http://www.tizag.com/cssT/cssid.php

Regards,
Paul

______________________________________________________________________
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