首页 > Web开发 > 详细

CSS垂直居中小结

时间:2017-06-07 20:22:46      阅读:282      评论:0      收藏:0      [点我收藏+]

1、设置子元素:

{
  ...
  position :absolute;
  margin:auto;   
  top:0;
  right:0;
  bottom:0;
  left:0;       
}

2、设置子元素:(height必须是固定值)

{
      position: absolute;
      top:50%;
      margin-top: - (0.5height);
}

3、设置子元素:(只适用于情况比较简单的单行文本)

{
  height:n px;
  line-height: n px; 
}

4、box 布局

5、transform

{
     position: absolute;
     top: 50%;  
     transform:translateY(-50%);  
}

  

CSS垂直居中小结

原文:http://www.cnblogs.com/JRliu/p/5940322.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!