I have a dynamic JS script that populates a bunch of divs with catalog information: image, title below image, text link below title. The images are all 150px square, but the title may be 1-3 lines in length. This means varying heights of divs, and they wrap. However, the divs are always 170px width.
Here’s the problem: when a div is extra tall in the middle of a row, then the next row starts to the right of that div, then the rest flows naturally, leaving an unsightly gap at the left.
How do you fix that? Eyeball the longest div and set a fixed height?
Here’s the relevant JS code I’m using:
output.innerHTML+="<div class='segment'><div class='segmentimg'><img class='pic' src='../images/parts/" + numb + "_sm.jpg' width='150px'>" + "</div>" +
"<p>#" + numb + " " + named + " <a href='/parts/details/" + numb + "/'>Online</a></p></div>";
And the relevant CSS:
.segment {
display:table-cell;
border-radius:8px;
background-color:#eee;
border:#878787 solid 1px;
padding:.5em;
margin:.5em;
-webkit-appearance:none;
overflow: auto;
width: 170px;
float: left;
}
.segmentimg {
float: left;
overflow: auto;
clear: right;
}
img.pic {
width:150px;
float: left;
}