关于CSS竖直垂直居中的方式

第一种

适用于固定宽高,设置top和left为50%;然后设置margin-left和margin-top为width和height的一半即可

width: 100px;
height: 100px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
background:#ffffff;

第二种

适用于不定宽高的,和第一种思路一致,但是使用translate来实现需要加上-webkit-前缀

width: 90px;
height: 130px;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
posted @ 2016-03-10 16:23  Colin_W  阅读(92)  评论(0)    收藏  举报