相对父元素永远垂直居中,水平居中也可以采用此方法。
parent{
position: absolute;
top: 0;
left: 0; //不会有滑动条出现,跟窗口一样大
height: 100%;
width: 100%; //窗口随动大小
}
chiled{
position: absolute;
height: 600px;
top: 50%;
margin-top: 300px; //这里为height的一半
width: 100%;
}