I have the following structure:
<div class="elementWrapper">
<div>1. Element</div>
<div>2. Element</div>
<div>3. Element</div>
<div class="alternate">1. Element with spec. Class</div>
<div class="alternate">2. Element with spec. Class</div>
<div class="alternate">3. Element with spec. Class</div>
<div class="alternate">4. Element with spec. Class</div>
<div class="alternate">5. Element with spec. Class</div>
<div>9. Element</div>
<div>10. Element</div>
<div>11. Element</div>
</div>
There can be a unknown number of multiple elements before and after, and I have no possibility to add a "wrapping" div around the elements with the class="alternate". (where everything would be fine).
I would like to give the first .alternate Element a border top, the last .alternate Element a border bottom. And all .alternate elements should have a different background color for each row (even/odd).
I've tried it in different ways, and I know that nth-of-type and nth-child won't work, because there is no wrapping div around my .alternate elements, and so it can't work because all Elements are counted for even/odd and so on.
So I made a pen with the problem and possible Solutions:
http://codepen.io/emjay/pen/RpyyOo
I would like to ask you, what the best way could be -without changing the structure-. Is there a working css only solution?
Thanks for your help!