Sent by Zoe M. Gillenwater on 29 September 2004 19:07
Jeff Ward wrote:
>So my question is about using classes as semantic groupings, as opposed to
>IDs. In my page instead of Adam's example of:
>#content p a { /* rules */ }
>
>I would use something like:
>.Content p a { /* rules */ }
>
>Is this worse for any reason?
>
Not necessarily, but you may run into specificity conflicts more often.
Since ID has such a great weight in terms of specificity, using the
selector "#content p a" you have a great chance of trumping other "a"
rules out there. With ".content p a" you may run into conflicts more
often, so just make sure you pay close attention to the order of rules
in your style sheet.
>I also have generalized classes, so I can
>have things like:
>.TableType1 { /* rules */ }
> .TableType1 .Header { /* rules */ }
>
>.TableType2 { /* rules */ }
> .TableType2 .Header { /* rules */ }
>
>So that changing the look of a table only requires I change the table's
>class, and not the rows surrounding it. Again, is this bad CSS programming?
>Is it better or worse? Is it even standards compliant!?
>
>
There's no way to tell whether you are doing something "badly" unless we
see it in context.
However, it looks like you are using more classes than you need, and
you're also not naming classes based on their meaning or content. What
is "TableType1" and how is it different from "TableType2"? If you could
name them "userInfoTable" and "productDetailTable" or whatever that
would be a lot better.
Or, does one type of table only appear on any given page? If so, you
could use descendant selectors:
body#users table { }
body#products table { }
That way you don't have to add classes to all the tables on the page,
just an id to the body. Again, I don't know if this makes any sense in
your case.
Also, try to style the "th" directly, instead of giving it a class of
"Header."
But, you may really need these classes -- I can't make any judgements
about your specific practices without seeing the big picture.
Zoe
--
Zoe M. Gillenwater
Design Specialist
Highway Safety Research Center
http://www.hsrc.unc.edu
______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
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/