Horizontally centring an element

code

  • padding: 0
    margin: 0
    box-sizing: border-box

main
width: 1100px
margin: auto
background-color: red

margin:auto

You can set the margin property to auto to horizontally centre


the element within its container.

The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.