navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Class & ID - Looking for some clarification

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> Cascading Style Sheets >> Class & ID - Looking for some clarification
Page: [1]
 
Donkey

 

Posts: 3842
Joined: 11/13/2001
From: Blackfield United Kingdom
Status: offline

 
Class & ID - Looking for some clarification - 9/1/2007 22:37:49   
I understand that IDs are used for items that appear only once on a page, and classes are used for items that appear multiple times on a page and like most of you I use both in the appropriate way.

But Why? The ID seems to be a waste of time - why not just use a class but, here's an idea, if you only want to use it once on a page you can, it works - I've done it.

ID's are great for identifying anchors so that you can link to a particular point on a page, but they really aren't much use in applying CSS rules; classes win every time.

To me there is no logic in having a "special" way of applying CCS rules to an element that only appears once on the page, I can't see that it serves any useful purpose. If it does why not have another for rules that only ever appear twice on a page, or three times or four?

Am I missing something or is the ID just pointless? I think we only use it because we are told we must and its continued use is just custom and practice.

I contend that the use of ID in this way is of no value because it doesn't make building the page easier, doesn't help the page to validate and doesn't make it more accessible.



_____________________________

:)

I have a higher and grander standard of principle than George Washington. He could not lie; I can, but I won't.
Samuel Clemens
d a v e

 

Posts: 4009
Joined: 7/24/2002
From: England (but live in Finland now)
Status: offline

 
RE: Class & ID - Looking for some clarification - 9/2/2007 1:44:29   
if i remember rightly id's have a greater weight - as far as inheritance goes - than classes, which could be useful

_____________________________

David Prescott
Gekko web design

(in reply to Donkey)
Tailslide

 

Posts: 5912
Joined: 5/10/2005
From: Out here on the raggedy edge
Status: offline

 
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.

_____________________________

"My strategy is so simple an idiot could have devised it"
Little Blue Plane Web Design | Blood, Sweat & Rust - A Land Rover restoration project

(in reply to d a v e)
Page:   [1]

All Forums >> Web Development >> Cascading Style Sheets >> Class & ID - Looking for some clarification
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts