JSFiddle - React, Tailwind, and code Playground
HTML
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
CSS
li{
width: 50px;
height: 50px;
background: red;
display: inline-block;
float: left;
list-style: none;
margin: 10px
}
li.hello{
background: green;
}
JavaScript
$(function(){
getLastItem();
$(window).resize(function(){
getLastItem();
});
function getLastItem(){
$('li').removeClass('hello');
var containerWidth = $('ul').eq(0).width();
var totalItem = $('li').length;
var itemWidth = $('li').eq(0).outerWidth(true); // plus margin
var itemPerRow = Math.floor(containerWidth/itemWidth);
var totalRows = Math.ceil(totalItem/itemPerRow);
$('li:nth-child(' + itemPerRow + 'n), li:last-child()').addClass('hello');
}
});