[thelist] CSS selectors

Stephen Rider evolt_org at striderweb.com
Wed Feb 25 17:04:48 CST 2004


(your example edited for clarity in the answer)

On Feb 25, 2004, at 1:56 PM, Alvaro Medina wrote:
> what is the difference between
>
> .someclass { }
> div.someclass { }

The first will apply to _any_ tag where class="someclass".  The second 
applies _only_ to a <div> where class="someclass"

> could one declare
>
> div.someclass { }
> p.someclass { }
>
> and so on? Is there a difference? Will the agent recognize it as 2 
> different classes?

Yes, these are two different things.  In practical terms, this can come 
into play if you are using classes in a true semantic sense.  In other 
words, if you are doing things like

class="bold"

and then setting it to boldface (not recommended), you can always come 
up with more different class names.  If, however, you're doing more 
semantic uses such as

class="featured"

you might have both divs and paragraphs that are "featured", and have 
different styles applied to them.

<tip type="Deciphering CSS Selectors">
Need to decipher the exact reference of a CSS selector?  check out the 
CSS SelectORacle at 
<http://penguin.theopalgroup.com/cgi-bin/css3explainer/selectoracle.py>

You feed it a CSS reference, and it describes its meaning in plain 
english (or Spanish!)
</tip>

Steve



More information about the thelist mailing list