Is there any difference between “margin: 0 auto;” and “margin: auto;”

前端 未结 1 358
执笔经年
执笔经年 2020-12-24 14:23

When we want page\'s main container align center, we usually use \"margin: 0 auto;\", but when I use \"margin:auto;\", behaviour are the same in so

相关标签:
1条回答
  • 2020-12-24 14:53

    Yes.

    margin: 0 auto;
    

    Sets the element's left and right margins to auto, and the top and bottom margins to 0.

    margin: auto;
    

    Sets all the margins to auto. You are probably getting the same behaviour due to your <body> being 100% height, hence the vertical auto margins have no effect.

    0 讨论(0)
提交回复
热议问题