一、根据子容器div大小设置偏移量使其垂直居中发布
1、方法:一先设置其水平和垂直偏移量分别为父级元素的50%(left/top)
二根据其本身大小将其向左向上移动一半大小(margin-left/margin-top)
html代码部分:
css 代码:
.block{
width: 900px;
height: 600px;
background-color: green;
position: relative;
margin: auto;
}
#wrap{
width: 300px;
height: 300px;
background-color: #1b6d85;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -150px;
}
二、不用考虑子容器的大小设置其垂直居中