加粗样式解决高度坍塌的方法
1.给父元素添加overflow:hidden;
弊端:这样会使超出的部分内容隐藏。
优点:写起来简单。
2.添加一个空的标签(例如:div)。
目的:是为了消除子元素的浮动。
代码:div{clear:both; height:0; width:0;overflow:hidden;}
3.万能清除法(推荐使用)
最近的父标签 ::after{content:“,”;display:block;
clear:both;width:0;height:0;}
注释:
1.content的属性值随便写。
2.display:block;是为了设置宽高。
3.clear:both;是为了清除浮动。
4.width:0;height:0;是为了优化。