I have 3 divs, A
, B
& C
, and each have 3 different backgrounds depending on which of the three div is hovered over.
The idea is to change background of the divs
as follows:
- On hover of
A
, changeA
background toa1
,B
tob1
andC
toc1
- On hover of
B
, changeA
background toa2
,B
tob2
andC
toc2
- On hover of
C
, changeA
background toa3
,B
tob3
andC
toc3
It seems that when trying to change the background of a div
that comes before the :hover
div
it fails.
HTML
<div class="team1"></div>
<div class="team2"></div>
<div class="team3"></div>
CSS
.team1 {
background: url("url of IMAGE1/a");
}
.team2 {
background: url("url of IMAGE2/a");
}
.team3 {
background: url("url of IMAGE3/a");
}
.team1:hover {
background: url("url of IMAGE1/b");
}
.team2:hover {
background: url("url of IMAGE2/b");
}
.team3:hover {
background: url("url of IMAGE3/b");
}
.team1:hover ~ .team2 {
/* this works */
background: url("url of IMAGE 2/c");
}
/* this works */
.team1:hover ~ .team3 {
/* this works */
background: url("url of IMAGE 3/c");
}
.team2:hover ~ .team1 {
/* this doesn’t work! */
background: url("url of IMAGE 1/c");
}