[thelist] I've found a great use for <span>

James Aylard evolt at pixelwright.com
Thu Aug 1 10:58:01 CDT 2002


Raymond,

> Ah, does this mean I can have 2 ids with the same name, but applied to
> different tags? Why would you use id instead of class?

    Within a given page, an id may occur only once. But you can use that
same id on another page, even applied to a different type of element, but
link the same style sheet to both pages. So, in page 1 I could have <td
id="SaleItem1">, and in page 2 I could have <h1 id="SaleItem1">. In such a
scenario, specifying the element name as part of the selector (e.g.,
td#SaleItem1) could be critical.
    The simple distinction between when to use an id and when to use a class
is: will this be a unique entity within the page? If so, use an id. But if
this will be one of a group of similar elements or elements that will share
similar styling characteristics, use a class. Ids are for individuals;
classes are for groups. And, of course, you can always apply both an id and
a class (or even multiple classes in most browsers) to a single element.

James Aylard




More information about the thelist mailing list