Assuming my body has background color of green,
when I do margin-left to my Div I can see the margin in a different color (green) and an overflow, but when I do margin-rigt the behavior is different, I see no margin nor overflow. Is there an explanation or reason fro it?
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: greenyellow;
}
.myDiv {
width: 100%;
height: 50px;
background-color: rgb(112, 112, 0);
/**margin-left: 50px;*/
margin-right: 50px;
}
<body>
<div class="myDiv"></div>
</body>
2
Answers
From the specification:
Note the
direction
which is very important and the default one is left-to-rightltr
In this case, it’s because you set the div’s width to
100%
. Try setting it toauto
.