1. 程式人生 > >不確定尺寸居中的辦法

不確定尺寸居中的辦法

transform 寬高 需要 style div orm bsp pre eight

不確定尺寸居中

.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;
}

不確定尺寸居中的辦法