please consider this code, why d3 and d4 are not aligned ?
what is the white space on top of d4 ?
.myContainer {
display: block;
}
#d3 {
width: 150px;
height: 150px;
border: 5px solid #aef704;
padding: 25px;
background-color: blueviolet;
box-sizing: border-box;
display: inline-block;
}
#d4 {
width: 150px;
height: 150px;
border: 2px solid #aef704;
padding: 25px;
background-color: brown;
box-sizing: border-box;
display: inline-block;
}
<html lang="en">
<head>
</head>
<body>
<div class="myContainer">
<div id="d3">test content d3</div>
<div id="d4">test content d4</div>
</div>
</body>
</html>
those 2 divs should both rendered inline-block and should have 150px width and 150px height, then why the second one is a little bit lower than the first one.
here is what rendered :
3
Answers
Because the default vertical alignment for inline elements is baseline. Change it easily by setting it to something like top instead.
Alternatively, use flex which is more robust. See usage here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
add this to your main container holding the two divs.