Previous Message
Next Message

Universal selector vs. body selector

Sent by Philippe Wittenbergh on 6 October 2009 15:03


On Oct 6, 2009, at 9:47 PM, Ezequiel Garzón wrote:

>  My doubt is,
> if the body contains all the other containers, why does body { ... }
> behave different from * { ... }? Aren't properties supposed to
> cascade? Inheritable properties at least, no? But then I find that
>
> body { color:black; }
>
> and
>
> * { color:black; }
>
> yield different results. For example, the links do not appear in black
> in the first case, even though the a selector lives inside the body
> selector and the color property is inheritable.

The universal selector (*) translates as 'select all elements on the  
page'. The 'body' selector translates as 'select the body element'.  
Now the 'color' property inherits, thus descendants of 'body' will  
also be coloured black (in your example, unless, and that is  
important, another style rule overrides this. This style rule may be  
part of the author stylesheet (the one you are writing), but that  
style rule may also be part of the UA stylesheet (by default, the UA,  
the browser) will style links, visited links differently from the  
surrounding text [1].

With the universal selector however, you declare that all elements  
will be coloured black. This will override the UA stylesheet. Bit a  
more specific selector can still override that, for example 'a  
{color:blue}'. This selector is more specific than the universal  
selector.

[1] and the style rule may also be part of a user stylesheet.

Philippe
---
Philippe Wittenbergh
http://l-c-n.com/





______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message

Message thread: