To select the succeeding elements, you would use the general sibling combinator, ~
.
Despite not being able to select the previous sibling elements, you could solve this by styling all the elements to begin with, and then overwriting the styling by selecting the succeeding elements.
This will set the color of all the elements (except .selected
) to red. It will then overwrite that styling and make the succeeding elements blue.
ul li:not(.selected) {
color:red;
}
ul .selected ~ li {
color:blue;
}
Since :not()
isn't supported in IE8, you could also use the following:
ul li {
color:red;
}
.selected {
color:black;
}
ul .selected ~ li {
color:blue;
}