To ask my question in some context, I have 12 sections that separate each other, each of which represents the month of the month. Either 0, 1, or 2 of these sections can be selected at a given time. When selected, the "active" class is applied to this div. When two divs are selected, I would like to apply style to all divs between the two selected.
eg.
<div class="month">Jan</div> <div class="month active">Feb</div> <div class="month">Mar</div> <div class="month">Apr</div> <div class="month">May</div> <div class="month">Jun</div> <div class="month active">Jul</div> <div class="month">Aug</div> <div class="month">Sep</div> <div class="month">Oct</div> <div class="month">Nov</div> <div class="month">Dec</div>
So, in the above snippet, I would like to apply the CSS style to the active months, as well as all the intervals between the months. Is this possible in CSS, or am I better with JS?
EDIT:
This does not work, but I think it might be on the right track.
.month.active ~ .month { background-color: $color-lighter-text; color: #fff; } .month.active:nth-child(2) ~ .month { background-color: #fff !important; color: $color-muted-text !important; }
source share