Can somebody explain to me what
margin : 15px auto;
does?
Thank you very much!
Can somebody explain to me what
margin : 15px auto;
does?
Thank you very much!
The margin (and padding) has a shortcut declaration that lets you set the top, right, bottom, and left sizes in one single declaration (rather than setting margin-top, margin-right, etc.). If you set just two sizes, it defines the top and bottom, then the sides.
The following declarations all have the same result:
div {
margin: 15px auto; /* top/bottom, then right/left */
}
div {
margin: 15px auto 15px auto; /* top right bottom left */
}
/* The long version... */
div {
margin-top: 15px;
margin-right: auto;
margin-bottom: 15px;
margin-left: auto;
}
As for what “auto” does, it just tells the browser to figure it out. You would usually do this to make a block element centered horizontally inside another, for example.
Thank you very much for your explanation.Clear and concise!