JSFiddle - React, Tailwind, and code Playground
by lukemartin
HTML
<div id="dv_frame"><div id="dv_images"></div></div>
CSS
#dv_frame {
width: 100%;
/*border: 1px solid #cccccc;*/
text-align: center;
height: 110px;
position: relative;
}
#dv_images {
/*border: solid 1px blue;*/
height: 100px;
margin: auto;
}
.myImage{
width: 100px;
height: 100px;
border: solid 1px red;
float: left;
margin-right: 5px;
margin-left: 5px;
}
JavaScript
var $container = $("#dv_frame"),
imageWidth = 110, // including margin & padding
imagesNeeded = Math.floor($container.width() / imageWidth), // rounded down, width/imageWidth
i, // iterator
$foo = $('<div></div>'); // empty container div
for(i = 0; i < imagesNeeded; i++) {
// appending to our empty container div
$foo.append("<div class='myImage'></div>");
}
// then appending the contents of our container div to the DOM.
// this is quicker and more efficient than doing lots of appends to the DOM in a loop.
$("#dv_images").append($foo.contents());