[thelist] #ID vs .Class
Andy Budd
andy at message.uk.com
Thu Apr 1 03:12:35 CST 2004
ID's should be used for named elements on a page that only appear once.
Generally people assign ID's to structural elements on a page such as
header, content, nav etc. ID's have a high specificity and will
generally override classes.
Classes are much more powerful than ID's as they allow you to create
custom styles that can apply to a large number of elements on a page.
For instance, you could have a class called error that turns the
background of an input box red or the colour of the text red in a span.
input.class {
background-color: red;
}
input.span {
color: red;
}
Elements can have multiple classes applied to them.
Chad Bishop wrote:
> I know that here and there I've read some good reasons to stick with
> using div id's where possible, instead of assigning classes. In my
> mind I know that this will better help to structure content, but we
> were having a discussion today at work, and I was asked why not just
> use classes? What specifically is the point of going with div id's
> first?
>
> Can someone point me towards some articles that address this directly?
> I'd like a good list of the practical benefits of using div id's to
> the fullest. And, classes where they should be.
Andy Budd
http://www.message.uk.com/
More information about the thelist
mailing list