JSFiddle - React, Tailwind, and code Playground
by Ajey
HTML
<div class="parent">
<div class="row">
</div>
</div>
CSS
body {
margin: 0;
padding: 0;
}
.parent {
font-size: 0;
}
.node {
background: #CCC;
height: 50px;
width: 50px;
margin: 2px 2px;
display: inline-block;
}
JavaScript
$(document).ready(function(){
var nodeDiv = '<span class="node"></span>';
var row = $('.row');
var node = $('.node');
var parent = $('.parent');
for(var i = 0; i< 50; i++) {
parent.append(nodeDiv);
}
var windowWidth = $(document).width();
var lastRow = Math.floor(windowWidth/54);
console.log("doc - ",lastRow);
lastRow = 50 % lastRow;
console.log(50 % lastRow);
var count = parent.children().length;
var lastChild = parent.children().last();
lastChild.css({'background':'red'});
for(var i=1; i < lastRow; i++) {
lastChild = lastChild.prev();
lastChild.css({'background':'red'});
}
});