Align dynamically created divs of varying heights
Created as answer to StackOverflow question http://stackoverflow.com/questions/13729070/trying-to-align-the-position-of-divs-which-are-of-different-sizes-so-that-ther
HTML
<div id="shadow"></div>
CSS
body {
margin:0px;
padding:10px;
background-color:#e0e0f0;
font-family:Arial;
color:#404040;
}
#shadow {
position:fixed;
top:0px;
left:0px;
width:100%;
height:100%;
padding:0px 0px 10px 0px;
box-shadow:0px 0px 20px #000000 inset;
}
h4 {
text-align:center;
margin:0px;
padding:10px 0px 10px 0px;
text-shadow:1px 1px 3px #404080;
}
p {
margin:0px;
padding:10px 15px 15px 15px;
font-size:15px;
}
div.column {
display:inline-block;
vertical-align:top;
width:240px;
height:auto;
padding:10px;
}
div.row {
width:240px;
height:auto;
margin:0px 0px 20px 0px;
padding:0px;
background-color:#f0f0f0;
border-radius:10px;
box-shadow:2px 2px 10px #808080;
}
img {
width:220px;
height:auto;
margin:0px 10px;
outline:1px solid #404040;
}
JavaScript
(function() {
window.addEventListener("load", function() {
var idw = 240 + 20, // Info-div width + horizontal margins & paddings & borders
data = {
base: "http://lorempixel.com/",
genres: [
"Fashion",
"Abstract",
"Animals",
"City",
"Food",
"Nightlife",
"People",
"Nature",
"Sports",
"Technics",
"Transport"
],
li: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
},
ww = window.innerWidth - 20,
numberofrows = 100, // for demo
cn = Math.floor(ww / idw),
dgl = data.genres.length,
lil = data.li.split(" ").length,
slsh = "/",
gnr = "",
ces = [],
cesl = 0,
nch = 0,
cc = 0,
sc = 0,
ch = 0,
c = 0,
nce,
nde,
nhe,
nie,
npe,
che,
shortest = function() {
sc = 0;
nch = 0;
che = ces[sc];
ch = Number(window.getComputedStyle(che).height.replace("px", ""));
while (++sc < cesl) {
nch = Number(window.getComputedStyle(ces[sc]).height.replace("px", ""));
if (nch < ch) {
ch = nch;
...