Fun with body IDs
Mark has hit on the clever idea of using the body tag’s id attribute to apply different styles to different pages all from the same stylesheet. The technique is very neat, but it would be even neater if he combined it with Eric Meyer’s CSS Signatures to allow advanced users to specify their own styles for his site. Since the ID attribute can’t be overloaded with more than one value doing so would probably mean having to use the body tag’s class attribute as well—the id attribute could hold the signature while the class attribute specified the page (or vice versa).
Kris - 16th January 2003 22:17 - #
Simon Willison - 16th January 2003 22:23 - #
Stuart Langridge - 17th January 2003 10:52 - #
From the XHTML1.0 spec:
Looks like ID is legal.
Kris - 17th January 2003 11:25 - #
Actually, the id attribute is only legal in XHTML. HTML 4 and older don't allow it.
And how exactly is this any better than <body id="my-domain-name" class="news" />?
Jan! - 17th January 2003 11:43 - #
It's better because it lets you style elements in the <head> as well.
Anyway, I've been using classes on <body> for like ever. :-) e.g. my blog puts class="index" on ln.hixie.ch if you are looking at it with the default settings (last ten entries).
Ian Hickson - 17th January 2003 12:35 - #
Xian - 17th January 2003 19:21 - #
Kris - 18th January 2003 16:55 - #
ashar - 29th January 2004 06:32 - #
Sebastiaan - 8th July 2004 17:27 - #
sammy - 17th April 2006 20:50 - #