0

I did a very simple demo in JSFiddle to illustrate my question.

I have two squares: a red #square1 and a blue #square2. What I want is very simple: when you hover the red square the other one turns red, and the same for the blue square.

The first one worked, using this code:

#square1:hover + #square2 {
  background-color: red;
}

The next effect did not work though. Used the ~ as I thought that that is what I should use for elements that are declared before?

#square2:hover ~ #square1 {
  background-color: blue;
}

How can I make it work using only CSS?

cabralpinto
  • 1,814
  • 3
  • 13
  • 32

0 Answers0