I've got 2 div tags: Div A and Div B. If Div B is hovered, then I need to changed background color of Div A. Can this be achieved with pure css only? I have already tried "~" "+" ">"
Asked
Active
Viewed 101 times
0
-
`if B is hovered change color of B.` .b:hover{...} – Bhojendra Rauniyar Jul 10 '15 at 11:19
-
2question..lol..correct it plz – Leo the lion Jul 10 '15 at 11:20
-
see to this http://stackoverflow.com/questions/1817792/is-there-a-previous-sibling-selector – Rohit Azad Malik Jul 10 '15 at 11:23
-
Put your HTML, we aren't wizards or witches to view trascendental codes. – Marcos Pérez Gude Jul 10 '15 at 11:52
3 Answers
0
Use Adjacent sibling selector +
<div class="a"></div>
<div class="b"></div>
.a:hover + .b {
background-color: red;
}
according to your previous words, this should be it. but let me know if your structure is more complex than this
-
In your code the bgcolor of B will changed what I'm asking is what if the reverse, when I focus/hover on B the bg color of A will changed.Thankz – eye Jul 10 '15 at 13:02
0
B:hover
{
background: #code;
}

Anuj Garg
- 584
- 7
- 22
-
if you can read the title then read back..op wants to change the background color of div a on hover of b..and use background-color rather then background when you know op wants to change color.. – Leo the lion Jul 10 '15 at 11:34
-
-
if you can read other answers or comment then you can see what everyone got.it was typo..sorry m not being rude but you should not mark these as answer..it can lead to wrong way.. – Leo the lion Jul 10 '15 at 11:39
0
I'm assuming you want to hover A
and change CSS of B
You may want to try this
.A,
.B{
width: 50px;
height: 50px;
border: 1px solid #000;
}
.A:hover+.B{
background-color: red;
}
<div class="A">A</div>
<div class="B">B</div>

Siddharth Thevaril
- 3,722
- 3
- 35
- 71
-
The OP already tried `+`. So do you think OP is looking for this? – Bhojendra Rauniyar Jul 10 '15 at 11:23
-
In your code the bgcolor of B will changed what I'm asking is what is the reverse, when I focus/hover on B the bg color of A will changed.Thankz – eye Jul 10 '15 at 12:56