There are two approaches you can take, to have a hovered element affect (E
) another element (F
):
F
is a child-element ofE
, orF
is a later-sibling (or sibling’s descendant) element ofE
(in thatE
appears in the mark-up/DOM beforeF
):
To illustrate the first of these options (F
as a descendant/child of E
):
.item:hover .wrapper {
color: #fff;
background-color: #000;
}
To demonstrate the second option, F
being a sibling element of E
:
.item:hover ~ .wrapper {
color: #fff;
background-color: #000;
}
In this example, if .wrapper
was an immediate sibling of .item
(with no other elements between the two) you could also use .item:hover + .wrapper
.
References: