水平居中

HTML

    <div class="center"></div>

方案1

.center {
            width: 100px;
            height: 100px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -50px;
            margin-top: -50px;
            background: red;
        }
        // 或者 margin 换成transform: translate(-50%,-50%);

方案2

 .center {
            width: 100px;
            height: 100px;
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin:auto;
            background: red;
        }

方案3 - flex

在center外层套一个DIV - container

#container{
    display:flex;
    justify-content:center;
    align-items: center;
}