I have discovered that by adjusting the display
property of the containing block to table
and enclosing descendant block boxes in boxes with display
property set to table-cell
and vertical-align
property set to top
, it produces the same effect as if the float
property of those boxes were set to left
.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>simulating float</title>
<style type="text/css">
#container {
background-color: darkgrey;
margin: 10px;
padding: 10px;
height: 240px;
display: table;
}
.box {
margin: 5px;
width: 240px;
height: 240px;
background-color: grey;
}
.float {
display: table-cell;
vertical-align: top;
}
</style>
</head>
<body>
<div id="container">
<div class="float">
<div class="box"></div>
</div>
<div class="float">
<div class="box"></div>
</div>
<div class="float">
<div class="box"></div>
</div>
</div>
</body>
</html>
Could someone help me understand this? Thank you.