I got the following HTML page with several pairs of DIV elements. These elements are generated with random values for the left margin.
Additional Information: DIV elements in the HTML file must remain in the specified 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 is as follows:

Is there a way to align div elements at the top of a page using pure CSS? DIV elements must add up if they are not completely next to the previous DIV. That is why elements 2 and 4 are in the second line. 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 explaining that the layout should work with randomly generated DIV elements:

, . , .
CSS , JS.