How to make padding:auto work in CSS?

前端 未结 5 898
孤街浪徒
孤街浪徒 2021-01-07 18:02

I am working on a legacy project that has CSS Reset with *{ margin:0; padding:0 } applied to everything. Now, my new code doesn\'t need that as it relies on Nor

5条回答
  •  心在旅途
    2021-01-07 18:15

    The simplest supported solution is to either use margin

    .element {
      display: block;
      margin: 0px auto;
    }
    

    Or use a second container around the element that has this margin applied. This will somewhat have the effect of padding: 0px auto if it did exist.

    CSS

    .element_wrapper {
      display: block;
      margin: 0px auto;
    }
    .element {
      background: blue;
    }
    

    HTML

    Hello world

提交回复
热议问题