Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help with css rules for hovering

Tags:

html

css

Given the following html:

<div>
  <div id="A1"></div>
  <div>
    <div id="B1" style="float:left;"></div>
    <div id="B2" style="float:left;"></div>
    <div style="clear:both;"></div>
  </div>
</div>

How do I make it so that hovering over 1B changes the bg color of 1A and 1B? Also, how do I make it so hovering over 2B changes the bg color of 1A and 2B? NO JAVASCRIPT.

For your added convenience, here is a jsFiddle to work from: http://jsfiddle.net/WJLGs/

like image 877
Dave Avatar asked Jan 27 '26 05:01

Dave


1 Answers

You can't. CSS has no selector that allows you to select an element based on its descendants or later siblings. The element you select has to be at the end of the chain.

You could match #1B or #2B based on #1A:hover, and you can match #2B based on #1B:hover — but they are all things that appear later in the document.

like image 152
Quentin Avatar answered Jan 28 '26 19:01

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!