margin:auto是具有強烈計算意味的關(guān)鍵字,用來計算元素對應(yīng)方向應(yīng)該獲得的剩余空間大小
填充規(guī)則
(1) 如果一側(cè)定值,一側(cè)auto,則auto為剩余空間大小
(2) 如果兩側(cè)均是auto,則平分剩余空間
<style>
.father {
width: 300px;
background-color: #f0f3f9;
}
.son {
width: 200px;
height: 120px;
margin-right: 80px;
margin-left: auto;
background-color: #cd0000;
}
</style>
<div class="father">
<div class="son"></div>
</div>

image.png