You can use the adjacent +
css sibling selector .
element1 + element2
means that he will select the second element element2
only if he immediately follows the first element element1
.
Stack fragment
.group-1+.group-2 {
margin-top: 50px;
}
.group-2+.group-3 {
margin-top: 50px;
}
<ul>
<li class="group-1">Group1</li>
<li class="group-1">Group1</li>
<li class="group-1">Group1</li>
<li class="group-2">Group2</li>
<li class="group-2">Group2</li>
<li class="group-2">Group2</li>
<li class="group-2">Group2</li>
<li class="group-2">Group2</li>
<li class="group-2">Group2</li>
<li class="group-3">Group3</li>
<li class="group-3">Group3</li>
<li class="group-3">Group3</li>
<li class="group-3">Group3</li>
<li class="group-3">Group3</li>
</ul>
Run codeHide resultLink Link adjacent sibling combinator
source
share