1.问题起因
高度不适应指的是,当内层对象的高度发生变化时,外层对象的高度不能自动进行调节,特别是当内层的对象使用margin或者padding只后。
如下:
1 2 3 4 5 6 7 8 | #box { background-color:#eee; } #box p { margin-top: 20px; margin-bottom: 20px; text-align:center; } |
解决:使用空div来占位
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #box { background-color:#eee; } p { margin-top: 20px; margin-bottom: 20px; text-align:center; } .clear-div { height:0px; overflow:hidden; } .box2 { background-color:#aaa; } |
或者为DIV加上border属性