|
Tailslide -> RE: Class & ID - Looking for some clarification (9/2/2007 3:16:48)
|
You could perfectly well build a site using classes only. There are a couple of reasons why using IDs can on some occasions make life easier: Firstly, if you're using scripting then you need IDs to identify an element using getElementById(). Secondly, as you point out - you can use them as anchors which is very useful. Thirdly, as Dave pointed out, although you can apply two classes to an element, an id will always hold precedence over a class placed on the same element no matter where on the stylesheet it's written. Usually with CSS the rule further down the stylesheet will overrule those preceding them - but with this for instance: #orange p {color:orange;}
.blue p {color:blue;} the paragraph will still be orange as the id has greater specificity. You'd have to add a class to the paragraph tag itself rather than just the div. Older browsers didn't understand multiple classes (class="big green") and you do have to be careful even now how you write out your styles concerning multiple classes as IE can mess things up for you if you try to be too clever. So in the end, yes you can perfectly well create a page without any IDs if you prefer and if you don't use either anchors or javascript. It comes down to personal preference - personally I feel happier giving the big, unique chunks of the page an id and then giving the smaller, repeated, non-structural stuff classes . But that's just a personal preference apart from the fact that I do use anchors and javascript.
|
|
|
|