Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

为什么很多父容器有高度的浮动元素前后还有::before,::after?父容器有高度,除了浮动元素没用其他元素

css新手,最近看各种网页源代码,为什么很多父容器有设置高度,而里面的浮动元素前后还要设置有::before,::after?父容器有高度,容器内除了浮动元素没有其他元素,不需要清除浮动啊?
谢谢!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

贴一下代码吧,伪元素能起到很多元素本身一样的作用,不止是清除浮动。有时候元素前后的装饰线可以用伪元素来实现。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...