1.垂直外邊距合并
主要發生在上下相鄰的元素之間和父子元素之間,解決方法有:
- 兄弟元素間設置float或inline-block或absolute
- 父子元素間設置border或padding隔開
- 設置margin時最好都使用一個方向top或buttom
2.清除浮動
- 添加空元素,應用clear: both
- 為父元素添加overflow: hidden
- after方法
.container{
*zoom: 1;
}
.container:after{
content: ' ';
display: block;
height: 0;
visibility: hidden;
clear: both;
}
- bootstrap中clearfix方法
.clearfix() {
&:before,
&:after {
content: " "; // 1
display: table; // 2
}
&:after {
clear: both;
}
}