auto 你可以理解為一種 自動/自適應 的概念 比如 現在項目需要一個寬度為960px的整體布局居中
根據用戶瀏覽器大小不同你將需要使用margin:0 auto;來實現。 無論用戶瀏覽器寬度為多少。
960px的定位寬度永遠居中。
css中的auto是自動適應的意思,而在css中auto往往都是默認值。
正如margin:0 auto,意思就是上下邊距為0,左右邊距為auto,就是自動適應。
但是,如果要使用他的話,就必須給標簽配上指定的寬度,如下:
<div class="center">居中</div>
<style type="text/css">
.center{
width:200px;
height:200px;
margin:0 auto;
}
</style>
另外,margin:0 auto 和 margin: 0 auto 0 auto 的效果是相同的。
都是指的上下邊距為0,左右邊距自動適應寬度相等。