...

View Full Version : Resolved CSS Parent's child?



shedokan
11-17-2008, 08:56 PM
how can I get to an element's parent's child?
this is my html:

<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:

.div .child-two:hover > child-one{
background:red;
}
but this doesn't work.
how can I do such a thing.
thanks in advance.

Apostropartheid
11-17-2008, 09:01 PM
What's wrong with using simply .child-one? What are you trying to do?

shedokan
11-18-2008, 03:07 PM
what I'm trying to do is make .child-one background red when you hover .child-two

jerry62704
11-18-2008, 03:31 PM
how can I get to an element's parent's child?
this is my html:

<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:

.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.

shedokan
11-18-2008, 03:46 PM
thanks, but isn't there a way to use a full path so Ie could understand too?

Apostropartheid
11-18-2008, 05:39 PM
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.

shedokan
11-18-2008, 05:56 PM
ok thanks for all the help.

VIPStephan
11-18-2008, 06:06 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum