I have a script (JsFiddle here) that detects when an li
block element is vertically centered on a page and assigns it a .centered
class to make it bigger via CSS.
.centered {
height: 30vh;
background-color: #bbb;
-webkit-transition: height 0.6s;
}
Once the central element is identified I manage to select the next sibling to via this:
.centered + li {
height: 20vh;
background-color: #ccc;
-webkit-transition: height 0.6s;
}
The problem arises when I try to select the sibling element preceding the .centered element in pure CSS
After looking at this question from 2011 I tried playing with the :has() pseudo class suggested in one of the comments and other selectors, but with no luck.
This CSS4 relational pseudo class could have done the trick, but is not currently supported:
li:has(+ .centered) {
height: 20vh;
background-color: #Fcc;
-webkit-transition: height 0.6s;
}
I also tried to select the last-of-type
of li
elements that are not siblings of .centered
, but either :not()
supports only simple selectors or I'm just not getting how to chain the selectors properly.
Here's the non-working selector:
li:not(.centered ~ li):last-of-type {
height: 20vh;
background-color: #Fcc;
-webkit-transition: height 0.6s;
}
QUESTION: Is there any combination of pseudo classes and selectors that could do the trick in pure CSS?
My hope is that some progress has been made since those questions have been asked.