码迷,mamicode.com
首页 > Web开发 > 详细

css中居中方法小结

时间:2017-10-25 21:45:47      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:pos   htm   abs   上下   经典   内容   size   --   居中   

---恢复内容开始---

1.文字垂直居中

.header_nav-item{
         height:38px;
         line-height:38px;
  }

 即文字所在模块的高度和行高设置成一样的!

2.块元素垂直居中与父元素 

.header_wrap{
      height:80px;
      position:realitive;
}
 
.header_logo{
      height:38px;
      position:absolute;
      top:50%;
      margin-top:-19px
}

  即父元素设置成相对定位,子元素设置成绝对定位,且子元素中top为50%,margin-top为-(负)height的一半。是一种比较经典的块元素居中法!

3.块元素(容器)水平居中    

.header_warp{
   margin: 0 auto;
}

 

即元素上下为0,左右设置成自动!

总之是很基础的方法,但经常用到,应该熟记!

 

---恢复内容结束---

css中居中方法小结

标签:pos   htm   abs   上下   经典   内容   size   --   居中   

原文地址:http://www.cnblogs.com/jianghao233/p/7731999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!