View video tutorial
CSS Margin Side
CSS
It sets the spacing around the elements from any direction outside the border.
CSS Margin
Margin can be set on each side of an element.
The following properties specify the margin for each side of an element.
margin-top
margin-right
margin-bottom
margin-left
Example
.p1 {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
Click on the "Try it Now" button to see how it works.
Margin Auto
Set the width of the element and set the margin property to auto to center the element horizontally within the container.
Example
button {
display: block;
width: 120px;
margin:auto;
padding-top: 15px 20px 15px 20px;
background-color: #128a00;
color: white;
font-size: 15px;
border: 1px solid #000;
border-radius: 5px;
}
Click on the "Try it Now" button to see how it works.