...

View Full Version : select all children



bcatt
06-27-2008, 07:17 PM
I want to select all children of a particular element to apply a style to, in particular, I would like to use this for positioning, where the parent element has relative positioning and the children have absolute positioning based on the parent. Does it have to look like so:


#top > p, a, div {position: absolute}

or is there and easier way where I can just say "select ALL children of this element and apply this style"?

Also, this particular div is not resizing itself to fit the child elements, while the children take up about 200X700 px of space, the div itself (when a border is added to make the size visible) is only a double line across the top of the page.

jerry62704
06-27-2008, 07:20 PM
I might be missing something obvious, but if you want the same style applied to everything under an object (and assuming individual items are not addressed elsewhere), wouldn't you just have:

#top { stuff; }

If the items are addressed elsewhere and that addressing is more specific, then you will have to add them to the list:

#top a, #top b { stuff;}

bcatt
06-27-2008, 07:27 PM
Well, what I have looks like so:


#top {
position: relative;
other styles
}

#childID1 {
position: absolute;
other styles
}

#childID2 {
position: absolute;
other styles
}

#childID3 {
position: absolute;
other styles
}

(#top being the parent element, and the others being children of #top) all the children are different types of elements, but I want to refer to them all to apply the absolute positioning, so that I don't have to retype that code for each child.

Apostropartheid
06-27-2008, 07:38 PM
or is there and easier way where I can just say "select ALL children of this element and apply this style"?



element > *
That won't work in IE6 as it's a direct selector, so perhaps you could use element * and zero out in element * *.

bcatt
06-27-2008, 07:48 PM
Thanks, I'll give it a try...

I've been using w3schools for learning css, but it seems a few things are not to be found there...is there a better resource?

ninnypants
06-27-2008, 07:56 PM
Try the Sitepoint (http://reference.sitepoint.com) reference.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum