Previous Message
Next Message

Re: [css-d] difference between class and id selectors

Sent by Ian Leckie on 31 January 2002 02:02


sure. . . I can answer that ;-)

ID is a unique selector. . .you can only use a particular value for and ID
once on a page. you can use the same value for a CLASS as many times as you
would like. you can also use them together.

it's handy for doing things like:

p.body {
    font: 14px/120% arial, sans-serif;
    margin: 4px auto;
    color: #000;
    text-indent: 6px;
    }

#first-para {
    font-weight: bold;
    }

and then:

<p class="body" id="first-para">

you can set most all of your properties for all of your body paragraphs
within p.body and just the properties that are different for the first
paragraph have to be defined within #first-para.


On 1/31/02 1:11 AM, "Jonathon Delacour" [EMAIL-REMOVED]> wrote:

> Encouraged by Eric Meyer's recent post encouraging all levels of questions,
> I'd like to ask about something that's been bugging me for a while.
> 
> I'm wondering if someone can succinctly explain (or point to an explanation
> of) the fundamental difference(s) between CLASS and ID selectors. In all
> the books and online resources I've looked at, the examples given seem to
> me to be applicable to either selector. As in <p class="first-para"> or <p
> id="first-para">.
> 
> To put it another way, are there circumstances in which one would always
> use an ID selector and not a CLASS selector (or vice versa)?

---
Ian Leckie
Interactive Developer
The Integer Group
[EMAIL-REMOVED]
p: 515.247.2646
c: 515.988.6003
Previous Message
Next Message

Message thread: