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

放肆的年华 提交于 2019-12-29 18:48:25

问题


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 some browser I have (Google Chrome, Firefox).


回答1:


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.



来源:https://stackoverflow.com/questions/8312354/is-there-any-difference-between-margin-0-auto-and-margin-auto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!