|
实现块级元素的垂直居中有多种方法,选用了如下方法:
.classify .c_items{
/*border: 1px solid green;*/
position: absolute;
top:0;
bottom:0;
left:0;
right: 0;
height: 40px;
margin: auto;
}原理: 父元素相对定位,子元素绝对定位,并且设置,top : 0 ; bottom: 0; 且,需要设置margin 为auto ,可以实现垂直居中; 但是在IE7下却不行。
解决: 使用另一种方法,top : 50% ,margin-top:-20px; 成功的实现了兼容。 .classify .c_items{
/*border: 1px solid green;*/
position: absolute;
top:50%;
left:0;
right: 0;
height: 40px;
margin: -20px auto 0;
} |
|