Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    32
    Thanks
    7
    Thanked 0 Times in 0 Posts

    select all children

    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:

    Code:
    #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.
    Last edited by bcatt; 06-27-2008 at 07:21 PM. Reason: additional question

  • #2
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    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;}
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    32
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Well, what I have looks like so:

    Code:
    #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.

  • #4
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Quote Originally Posted by bcatt View Post
    or is there and easier way where I can just say "select ALL children of this element and apply this style"?
    Code:
    element > *
    That won't work in IE6 as it's a direct selector, so perhaps you could use element * and zero out in element * *.

  • Users who have thanked Apostropartheid for this post:

    bcatt (06-27-2008)

  • #5
    New Coder
    Join Date
    Mar 2008
    Posts
    32
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Try the Sitepoint reference.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •