0

I want to make :hover changes on child element.

Let's say I have the below HTML:

<div class="wrap"> <div class="adjacent_sibling">Placeholder text</div> <div class="adjacent_sibling class">Placeholder text</div> </div> 

I can make changes on the child element with CSS like this:

.wrap:hover .class { /*CSS to come here*/ } 

but can't I make changes like this:

.wrap:hover + .wrap > .adjacent-sibling{ /*CSS to come here*/ } 

or:

.wrap:hover + .adjacent-sibling { /*CSS to come here*/ } 

How can this be achieved? I need to target the adjacent sibling if it is the child (children). This is for learning purposes only.

4
  • I have edited my question. Commented Oct 28, 2016 at 12:19
  • You need to read basics Commented Oct 28, 2016 at 12:21
  • Read it long time ago. I need to target the adjacent sibling if it is the child (children). Commented Oct 28, 2016 at 12:22
  • 1
    "I need to target the adjacent sibling if it is the child" - it can only be either a sibling, or a child. Both together is impossible. Commented Oct 28, 2016 at 12:50

1 Answer 1

4

+ Refers to the neighbor element and not to children.

If you want its need to be like this:

.wrap:hover > .adjacent-sibling, .wrap > .adjacent-sibling { /*CSS to come here*/ } 

or:

.wrap:hover > .adjacent-sibling { /*CSS to come here*/ } 

Edit: How target adjacent siblings in the children:

.wrap:hover > .adjacent-sibling + .adjacent-sibling.class { /*CSS to come here*/ } 
Sign up to request clarification or add additional context in comments.

5 Comments

I have already wrote this. How can I target adjacent siblings in the children?
@stormec56 You nedd to use child-selector as @Zeev Katz said above.
And that is the answer to my question! thanks mate. :)
Edit my answer my friend
+ does not refer to the next, but the neighbor element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.