[Javascript] using multiple class names
Paul Novitski
paul at novitskisoftware.com
Wed May 26 13:12:38 CDT 2004
At 06:32 AM 5/26/2004, Mike Dougherty wrote:
>I'm already naming most of my objects with Id attributes. Are there any
>caveats against using the id reference in CSS? ex: #ID1 {*style*} This
>formatting is not DHTML (en/dis-abled, etc.) so it won't need to be
>referenced dynamically. So rather than using a class name with only one
>member, I figured I could just use the #ID syntax. I did see a reference
>to this being "limited" somehow, but it wasn't explained why. Any thoughts?
I myself haven't run into any problems using object ids as CSS selectors.
My personal guideline is simply: if I need to distinguish a single object
on the page, I give it an id; if more than one object can fit into the same
category, I give it a class:
<div id="bookmenu" class="dropdown">
<div id="chaptermenu" class="dropdown">
<p class="caption">
I guess it all depends on whether you conceive of the object as unique or
belonging to a type.
___________________________
One advantage to giving the outermost container an id is that it lets you
control its nested inner objects merely by their tagname:
#topmenu ul li a {}
.body p span {}
I find this greatly reduces the number of classes & ids I need to embed in
my HTML.
___________________________
Tangentially, I used to code my CSS using the HTML tag consistently:
div#topmenu {}
but have lately taken to dropping the tag from CSS:
#topmenu {}
when the specific tag I've chosen (div or p or span or whatever) isn't
pertinent to the structure. That way I can always change the tag if I need
to without having to modify the CSS. I guess that could be an argument for
using id & class selectors exclusively, but I love the brevity of coding
CSS with tagnames (#menu ul li ul li a).
In CSS-D, Peter-Paul Koch just brought up a problem he discovered with
Mozilla recognizing the .test:hover selector, so I guess it's not safe
always to drop the tag name.
Cheers,
Paul
PS: This discussion is Off Topic and probably should be scooted over to
another forum. I personally enjoy CSS-D admin'd by Eric Meyer:
http://www.css-discuss.org/mailman/listinfo/css-d
More information about the Javascript
mailing list