I'm wondering why these selectors produce same result
#position2{
margin-left:25px;
}
#position3{
padding-left:25px;
}
<h1 id="position2">Stackoverflow</h1>
<h1 id="position3">Stackoverflow</h1>
I'm wondering why these selectors produce same result
#position2{
margin-left:25px;
}
#position3{
padding-left:25px;
}
<h1 id="position2">Stackoverflow</h1>
<h1 id="position3">Stackoverflow</h1>
Sure!
So the margin
is added outside of the element you've targeted - in this instance it is placed to the left of the outside of the #position2
div.
padding
, on the other hand, is added inside the element you've targeted. The easiest way to see this is by adding a background color to the code you've already got:
#position2{
margin-left:25px;
background-color: blue;
}
#position3{
padding-left:25px;
background-color: red;
}
This then outputs this, giving a clear visual representation of what's happening: