I've got a project wherein I have no control whatsoever over the markup. I'm looking for a way to select every instance of 'class2' that immediately follows an instance of 'class1'. The following strategy works, but in some cases there are over 20 instances of 'class2' in a row and I'd prefer to avoid that huge mess in my code.
.class1 + .class2, .class1 + .class2 + .class2, .class1 + .class2 + .class2 + .class2, .class1 + .class2 + .class2 + .class2 + .class2, .class1 + .class2 + .class2 + .class2 + .class2 + .class2 // etc. { // Applied Styles } ...to style the following
<div class="class1"></div> <div class="class2">Style Me!</div> <div class="class2">Style Me!</div> <div class="class2">Style Me!</div> <div class="class2">Style Me!</div> <p>Blah blah blah</p> <div class="class2">DO NOT STYLE ME</div> <div class="class2">DO NOT STYLE ME EITHER</div>
.class1 .class2 {/*styles*/};