I got the following HTML page with just a couple of DIV-elements. These elements are generated with random values for the left margin.
Additional Info: The DIV-elements in the HTML file have to stay in the given order.
<html>
<head>
<style type="text/css">
.box{
height: 50px; width: 50px; border: 1px solid black;
text-align: center; margin-bottom: 5px;
}
</style>
<title></title>
</head>
<body>
<div class="box">1</div>
<div class="box" style="margin-left: 30px">2</div>
<div class="box" style="margin-left: 90px">3</div>
<div class="box" style="margin-left: 120px">4</div>
<div class="box" style="margin-left: 240px">5</div>
</body>
</html>
The resulting page looks like this:
Is there a way, to align the DIV-elemets to the top of the page with pure CSS? DIV-elements should stack up, if they aren't completely beside the preceding DIV. That is why element 2 and 4 are in the second row. Since there is no 'float: top;' command, I have no idea how to achieve the following layout:
Since my problem is still not clear, here is another example to clarify, that the layout should work with random generated DIV-elements:
If the element does not fit beside the preceding element, it should stack up. If it fits, it should align to the top.
If there is no way with pure CSS, a JS workaround would also be possible.