fjckls fjckls - 4 months ago 30
CSS Question

Select previous and next sibling of an active element

I want to select one element before and one element after the given class with CSS only. I'm wondering if that's possible ... Here is my list:

<li class='active'>three</li>

I want to apply some styles to one element before and one after
. I can do it with javascript - no problem, but I was wondering if something like this could be possible:

/* before .active */
ul - 1) {
/* after .active */
ul + 1) {


You Can't select previous sibling. But yes you can select next sibling by

ul li{

Js fiddle Link

You can select previous sibling by Javascript.