1.已知大小(定宽高)的元素在屏幕窗口水平垂直都居中
方案:元素{
width:数值+单位;
height:数值+单位;
position:fixed;
left:50%;
top:50%;
margin-left:-width/2+单位;
margin-top:-height/2+单位;
}
2.未知大小(不定宽高)元素在屏幕窗口水平水平垂直都居中
方案:元素{
position:fixed;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}
3.使用css3变形的方式实现不定宽高元素在屏幕窗口水平垂直都居中
方案:元素{
position:fixed;
left:50%;
top:50%;
transform:translate(-50%,-50%);
}