登录框 纯css自适应居中

用margin负值与50%定位,实现自适应居中。

<div class="login-box">
    /*input*/
</div>
<style>
    .login-box{
        width:500px;
        height:400px;
        margin: -200px 0 0 -250px;
        position: absolute;
        top: 50%;
        left: 50%;
    }
</style>

另一种方法,利用transform变换

.class{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: auto;
    height:auto;
}

猜你喜欢

转载自blog.csdn.net/xiaoxiaohai0000/article/details/80038691