body {
border: 2px solid black;
height: 100px;
}
div {
vertical-align: middle;
display: inline-block;
width: 50px;
height: 50px;
}
.a {
border: 2px solid red;
margin-top: 20px;
}
.b {
border: 2px solid green;
}
<!DOCTYPE html>
<html>
<body>
<div class="a">a</div>
<div class="b">b</div>dsfdg
</body>
</html>
Why are both the blocks not aligned to the middle ? why is there a strange space between upper border of body and upper border of block b? Should not something like this happen without adding top margin to block b (in this case i added margin-top to the block b myself)?
body {
border: 2px solid black;
height: 100px;
}
div {
vertical-align: middle;
display: inline-block;
width: 50px;
height: 50px;
}
.a {
border: 2px solid red;
margin-top: 10px;
}
.b {
margin-top: 10px;
/*should not block b come automatically 10 px down without adding top margin to it */
border: 2px solid green;
}
<!DOCTYPE html>
<html>
<body>
<div class="a"></div>
<div class="b"></div>dsfdg
</body>
</html>