2

How can I change the styles of my div's 2 siblings when hovering over it?

#magic:hover + (#sibling1 > span, #sibling2 > span){color: blue}

JSFiddle

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
hjef
  • 45
  • 5
  • 1
    See also: [Are parentheses allowed in CSS selectors?](http://stackoverflow.com/questions/5478920/are-parentheses-allowed-in-css-selectors) and [CSS combinator precedence?](http://stackoverflow.com/questions/3851635/css-combinator-precedence) – BoltClock May 19 '14 at 17:05

2 Answers2

1

UPDATED this fiddle

#magic:hover ~ .box span {color: blue}

edited use the above instead, apparently + only works with immediate sibling http://www.sitepoint.com/web-foundations/adjacent-sibling-selector-css-selector/

nolawi
  • 4,439
  • 6
  • 22
  • 45
0

Why not use adjacent selector to achieve that?

#magic:hover + #sibling1 + #sibling2 span {
    color: red;
}

Demo (Hover the first element and see the color changes for the 3rd element)

And if you want to change the styles of all the element followed by #magic, than use

#magic:hover + #sibling1 span,
#magic:hover + #sibling1 + #sibling2 span {
    /* Styles goes here */
}

Demo 2

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278