The row
div has a top/bottom margin of 10px (margin: 10px 2px
). However, the 10px
is pushing the position of the main container. What I am trying to achieve is the row has a top/bottom margin inside the main-container
. The margin is some how escaping and pushing the main-container
.
Here is my code:
body {
padding: 0;
margin: 0;
}
.main-container {
position: relative;
display: block;
width: 183px;
height: 101px;
background-color: red;
}
.row {
position: relative;
display: block;
margin: 10px 2px;
width: 175px;
height: 15px;
background-color: green;
}
<div class="main-container">
<div class="row">
</div>
<div class="row">
</div>
</div>
But if you run this code (below), without the row
div. You can see the position of the main-container
is different. This is the position the main-container
should be in.
body {
padding: 0;
margin: 0;
}
.main-container {
position: relative;
display: block;
width: 183px;
height: 101px;
background-color: red;
}
<div class="main-container">
</div>
How can I fix this?