页面垂直居中

Posted liuzhouyuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了页面垂直居中相关的知识,希望对你有一定的参考价值。

<div id="popup"></div>

 

需要定义heigh 和width

#popup
position:fixed
left:0
right:0
top:0
bottom:0
width:100px
height:100px
margin:auto
background:red
color:#fff

 

 

不需要定义高宽

#popup
position: fixed;
left: 50%;
top:50%;
background: rgba(0,0,0,.35);
padding: 10px;
border-radius: 5px;
transform: translate(-50%,-50%);
color:#fff

 



















以上是关于页面垂直居中的主要内容,如果未能解决你的问题,请参考以下文章