不确定尺寸居中的办法

不确定尺寸居中

.demo {
    position: absolute;
    top: 50%;
    left: 50%;
     transform: translate(-50%,-50%)
}

而另外一种使用margin的,这种是需要知道居中元素的宽高才能实现的

.demo {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    margin-left: -50px;
    margin-top: -50px;
}

 

posted @ 2017-07-19 16:58  无情码字员  阅读(253)  评论(0编辑  收藏  举报