...

View Full Version : CSS ">" question



glenmac
03-10-2005, 05:10 PM
I've searched but can't find the answer. What does the ">" mean in this CSS code?

body > html{color:red;}

channy
03-10-2005, 06:07 PM
it's a child selector

E > F Matches any F element that is a child of an element E. Child selectors

Selectors (http://www.w3.org/TR/REC-CSS2/selector.html)

pb&j
03-10-2005, 06:50 PM
would that have the same effect as this then?

html body {color:red;}

evo
03-10-2005, 07:00 PM
Well glenmac's version is the wrong way round, and pb&j, yup.

AaronW
03-10-2005, 07:44 PM
would that have the same effect as this then?

html body {color:red;}

No. The child selector selects children only, whereas that selects ALL descendants.

Edit: Though in this example the effect is the same, but only in certain browsers. IE, for example, will ignore html > body. IE will ignore the child selector, period.

pb&j
03-10-2005, 09:45 PM
No. The child selector selects children only, whereas that selects ALL descendants.
ok, so i get understanding this correctly...

tag1 > tag2 {style;}
this ^ will apply the style to items in the tag2 area only. if there are other tag areas inside tag2, they will not be styled by this.

tag1 tag2 {style;}
this ^ will apply the style to items in the tag2 area fully. if there are other tag areas inside tag2, they will be styled by this as well.

is that right?

AaronW
03-11-2005, 12:26 AM
Yes. It just prevents cascading to grandchildren. Very useful, but unsupported by IE so virtually useless for any practical Web sites. Thankfully, my homepage doesn't aim to be practical so I'll be using that selector to generate my multi-level menu with CSS :)

http://v3.offtone.com/ - An example of how it can be used (that page may be fubared when you look at it as I could be working on it)

glenmac
03-11-2005, 07:05 PM
Thank you for your explanation.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum