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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Question CSS Parent's child?

    how can I get to an element's parent's child?
    this is my html:
    Code:
    <div class="div">
    <div class="child-one">Child 1</div>
    <div class="child-two">Child 2</div>
    <div class="child-three">Child 3</div>
    </div>
    I am trying this code:
    Code:
    .div .child-two:hover > child-one{
    background:red;
    }
    but this doesn't work.
    how can I do such a thing.
    thanks in advance.
    Last edited by shedokan; 11-18-2008 at 05:57 PM.

  • #2
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    What's wrong with using simply .child-one? What are you trying to do?

  • #3
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    what I'm trying to do is make .child-one background red when you hover .child-two

  • #4
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    Quote Originally Posted by shedokan View Post
    how can I get to an element's parent's child?
    this is my html:
    Code:
    <div class="div">
    <div class="child-one">Child 1</div>
    <div class="child-two">Child 2</div>
    <div class="child-three">Child 3</div>
    </div>
    I am trying this code:
    Code:
    .div .child-two:hover > child-one{
    background:red;
    }
    but this doesn't work.
    how can I do such a thing.
    thanks in advance.
    Child-one would have to be a direct child of child-two for that to work. It's not defiined that way, however so therefore it can't work.

    An elements parents child is that element and its siblings. If you want them, use the "+" operator, not the ">" one. But I'm not sure IE supports this at all, at least in IE6 and down.
    .
    .
    ...and gladly would he learn and gladly teach

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

  • #5
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    thanks, but isn't there a way to use a full path so Ie could understand too?

  • #6
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Quote Originally Posted by shedokan View Post
    thanks, but isn't there a way to use a full path so Ie could understand too?
    ...No. At least, not in pure CSS. I'm sure there'd be a way using JavaScript or an expression.

  • #7
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    ok thanks for all the help.

  • #8
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,865
    Thanks
    6
    Thanked 1,028 Times in 1,001 Posts
    Also, in CSS there is no “previous sibling” selector or any reverse selector at all. You could only have something like .child-one:hover + .child-two. You can only style a next sibling or child element, not a previous sibling or parent element. After all, CSS means cascading stylesheet and a cascade can’t go backwards.


  •  

    Posting Permissions

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