首页 > 文章列表 > css margin:auto的填充规则

css margin:auto的填充规则

css margin:auto
469 2022-08-06

说明

1、如果一侧定值,包括不设定值取默认值0的情况,一侧auto,则auto为剩余空间大小。

2、如果两侧均是auto,则平分剩余空间。

实例

<style>
    .father {
      width: 300px;
      background-color: #f0f3f9;
    }
    .son {
      width: 200px;
      height: 120px;
      margin-right: 80px;
      margin-left: auto;
      background-color: #cd0000;
    }
  </style>
 
<div>
    <div></div>
  </div>

本文教程操作环境:windows7系统、css3版,DELL G3电脑。