Let me visually demo the result first. (you can see this by expanding the code snippet to full page)
With the source HTML / CSS code below.
<!DOCTYPE html>
<html>
<head>
</head>
<style>
.container{
height: 400px;
width: 400px;
border: 2px solid black;
display: inline-block;
position: relative;
}
.box{
height: 100px;
width: 100px;
border: 1px solid gray;
display: inline-block;
}
.box1{
height: 100px;
width: 100px;
border: 1px solid gray;
position: absolute;
}
.box2{
height: 100px;
width: 100px;
border: 1px solid gray;
position: absolute;
left: 100px;;
}
.box3{
height: 100px;
width: 100px;
border: 1px solid gray;
position: absolute;
left:200px;
}
.box4{
height: 100px;
width: 100px;
border: 1px solid gray;
position: relative;
left:300px;
}
</style>
<body>
<div class="container">
<div class="box1">position absolute</div>
<div class="box2">position absolute</div>
<div class="box3">position absolute</div>
<div class="box4">position absolute</div>
</div>
<div class="container">
<div class="box">display: inline-block, position: static</div>
<div class="box">display: inline-block, position: static</div>
<div class="box">display: inline-block, position: static</div>
<div class="box">display: inline-block, position: static</div>
</div>
</body>
</html>
I am wondering why there is a space in the upper left side of this layout.
Originally, I thought the two large box(outer square) should alight the height because both of them are display:inline-block
.
Really wondering how the CSS calculate and decided to show this result under the hood.
Thanks in advance!