CSS margin property for centering an element
You can center elements, using the margin
property. You take both individual margin-left
and margin-right
properties and set them to the auto
value. What happens when you apply this value only to the left or right margin? The element is pushed to the opposite side of the container, while the left/right margin receives a large share of the unused horizontal space.