首页 > IT职业 > IT图书 > 解决margin-top塌陷,实现子元素动态改
/*伪类解决margin-top塌陷*/.clearfix:before{ content:""; display: table;
}
解决margin-top塌陷
html>margin-top塌陷
.clearfix:after{ content: ""; display: table; clear:both;
}
子元素动态改变父元素尺寸
html>浮动子元素宽度
以上两种情况极其常见,解决方式也很类似,所以可对两种方式做一个封装:
.clearfix:before, .clearfix:after{ content: ""; display: table;
}.clearfix:after{ clear:both;
}/*适配非主流浏览器(IE浏览器)*/.clearfix{ zoom:1;
}
以后遇到上面两种问题,只要将 小结 中的源码引入到对应的css(层叠样式表),最后在父元素class属性中 中引入clearfix即可
h1,h2,h3,h4,h5,h6,p,body,ul,ol,dl,dd,dt,input{ /*去掉默认样式*/
margin: 0; padding: 0;
}ul,ol{ /*去掉左边的点或者数字*/
list-style: none;
}a{ /*去掉下划线*/
text-decoration: none;
}em,i{ /*去掉斜体*/
font-style: normal;
}b,strong{ /*去掉加粗*/
font-weight: normal;
}/*清除浮动影响 和清除margintop塌陷 合在一起的写法*/.clearfix:before,.clearfix:after{ content: ""; display: table;
}.clearfix:after{ clear: both;
}.clearfix{ /*兼容ie*/
zoom:1;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/875/viewspace-2804086/ ,如需转载,请注明出处,否则将追究法律责任。