In the code below, why do I need to set vertical-align: top
to both elements to close the gap between them? If the gap occurs on the first element only, can't I just set that to vertical-align: top
to close the gap?
Here is what occurred if I assign vertical-align property to only .test
:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
body{
width: 100vw;
height: 100vh;
margin: 0;
background-color: black;
}
.test {
vertical-align: top;
display: inline-block;
width: 10%;
height: 100px;
background-color: lightblue;
}
hr{
display: inline-block;
width: 100%;
border: thick solid lightgreen;
margin: 0;
}
</style>
</head>
<body>
<div class = "test"></div><hr/>
</body>
</html>
This is what happened when I assign vertical-align to both elements:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
body{
width: 100vw;
height: 100vh;
margin: 0;
background-color: black;
}
.test {
vertical-align: top;
display: inline-block;
width: 10%;
height: 100px;
background-color: lightblue;
}
hr{
display: inline-block;
width: 100%;
border: thick solid lightgreen;
margin: 0;
vertical-align: top;
}
</style>
</head>
<body>
<div class = "test"></div><hr/>
</body>
</html>