[thelist] CSS id or class?

Simon Dell simondl at epic.co.uk
Thu Aug 1 10:59:08 CDT 2002


At 11:10 01/08/02 -0400, you wrote:

> > What scenarios call for either or both?
>
>lots...

*jumping in feet first*
Just as an example of a situation using both.. Something I was quite proud
of was a set of menu items which were all of a particular style, but
scattered liberally about the page (not my design, I only code these things...)

So all the links had a class of "menuItem" and an id of "item1", "item2"
... "itemX".
This meant I could do the following in CSS:

.menuItem {
position: absolute:
height: 10px;
width: 100px;
/* some colour, some font stuff, backgrounds, padding etc */
}

#item1 { left: X1px; top: Y1px;}
#item2 { left: X2px; top: Y2px;}
.. and so on.

Things like this, to me at least, make the code very easy to modify, in a
logical way. The look and feel of the items can be changed collectively
without having to alter their positioning, and the _important_ code
controlling their position (just those items than can change, and nothing
else) was kept to a minimum so it's nice and easy to update.

Only tested on IE5 and 5.5 Windows.. I can see no real problem why it
wouldn't work on most other platforms - normal nn4 disclaimers apply! ;-)

Hope that's useful.
Simon





More information about the thelist mailing list