码迷,mamicode.com
首页 > 其他好文 > 详细

【技术】高度不适应(内层对象高度发生变化时,外层对象的高度不能自动调节)

时间:2015-08-26 10:39:02      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

html部分:

<div class="box2">上</div>
<div id="box">
<p>内容<br>内容<br>内容<br>内容<br>内容<br>内容</p>
</div>
<div class="box2">下</div>

 

css部分:

.box2{
  background-color: #ccc;
}
#box{
  background-color: #eee;
}
#box p{
  margin: 20px 0;
  text-align: center;
}

注:对1px间距没有要求的时候用法一、法二,要求严格用法三

法一:

技术分享

#box{
  background-color: #eee;
  border: 1px solid #fff;/*添加代码*/
}

法二:     

技术分享

 

#box{
  background-color: #eee;
  padding: 1px 0;/*添加代码*/
}

法三:

技术分享

html部分:

<div class="box2">上</div>
<div id="box">
  <div class="clear-div"></div>
  <p>内容<br>内容<br>内容<br>内容<br>内容<br>内容</p>
  <div class="clear-div"></div>
</div>
<div class="box2">下</div>

 

css部分:

.box2{
  background-color: #ccc;
}
#box{
  background-color: #eee;
}
#box p{
  margin: 20px 0;
  text-align: center;
}
.clear-div{
  height: 0;
  overflow: hidden;
}

                                                             

【技术】高度不适应(内层对象高度发生变化时,外层对象的高度不能自动调节)

标签:

原文地址:http://www.cnblogs.com/ybingbing_1213/p/4759595.html

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