I am trying to make a harmonic effect by changing the height of the divs while hovering over another.
My HTML looks like this:
<html><body> <div class="section1"></div> <div class="section2"></div> <div class="section3"></div> <div class="section4"></div> </body></html>
Each section has a height of 25%. When hovering over section 1, all other divs should decrease in size, while section1 expands. This is easy to do with the following CSS:
.section1 { height: 40%; } .section1:hover ~ div:not(section1) { height: 20%; }
The problem is that ~ selector selects only divs div divs below the current div. Therefore, if I use the same code for section 2, this will only affect section3 and section4. Section 1 will have an original height of 25% because it is taller than the current div.
Is it possible to solve this problem only with CSS?
source share