I am facing a challenge with my HTML code and styling, which is just an example:
<div id="mn" style="margin-top:200px;">
<div class="first">1</div>
<div class="second">2</div>
<div class="third">3</div>
<div class="fourth">4</div>
</div>
<style type="text/css">
#mn, #mn div { display:inline-block; vertical-align:middle; }
#mn div { width:350px; margin:5px; /* float:left Comment */ }
div.first { height:5px; background-color:Red; }
div.second { height:120px; background-color:#999 }
div.third { height:50px; background-color:Yellow }
div.fourth { height:180px; background-color:#ccc }
</style>
The issue at hand is that the elements on the left side (the yellow and red ones) have excessive spacing between them. I aim to eliminate this large margin or spacing and maintain a consistent 5px margin for all elements.
In an attempt to address this, I devised a JQuery script to rearrange the list into divisions as follows:
<div id="mn_left"></div>
<div id="mn_right"></div>
<div id="mn" style="margin-top:200px;">
<div class="first">1</div>
<div class="second">2</div>
<div class="third">3</div>
<div class="fourth">4</div>
</div>
$(document).ready(function () {
$("div", "#mn").each(function (e, value) {
if ($("#mn_left").height() <= $("#mn_right").height()) {
$("#mn_left").append(value.outerHTML);
}
else {
$("#mn_right").append(value.outerHTML);
}
});
});
While the script does the job effectively, I seek a solution that doesn't involve scripts.
Edit... I made an error by swapping li tags for divs, but the concept remains the same. The HTML now appears like this:
My ultimate goal is represented in the following image: