So I've been able to detect the number of siblings an element has by using nth-child(), however I haven't been able to figure out a way to select only the last few elements based on the total number of siblings.
In the following code snippet, I've achieved the goal I wanted by adding classes. But I would like a way to achieve this with just CSS selectors, if possible. In the following code snippet, each "group" has 2 rows, a row being defined as 3 elements together. I would like to select the orange elements as seen in the snippet below without adding classes. Either selecting the elements in the last row or selecting all of the elements except for those in the last row.
ul {
padding-left: 0;
}
ul::after {
content: '';
display: table;
clear: both;
}
li {
background-color: #efefef;
border: 1px dotted #000;
box-sizing: content-box;
float: left;
list-style-type: none;
padding: 10px 0;
text-align: center;
width: 33%
}
.alt {
background-color: orange;
}
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li class="alt">4</li>
</ul>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li class="alt">4</li>
<li class="alt">5</li>
</ul>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li class="alt">4</li>
<li class="alt">5</li>
<li class="alt">6</li>
</ul>