clearfix 是一种元素自动清除或修复其元素的方式,因此不需要添加额外的标记。它通常用于浮动布局,其中元素浮动以水平堆叠。如果元素比包含它的元素高,那么使用 CSS 的溢出属性来克服这个问题。
例子:
在上面的图像中,徽标不适合 div 元素。要解决这个问题,有两种方法。首先是通过增加 div 块的高度,其次是通过使用 clearfix CSS 属性。
示例 1:在下面的代码中,问题在不使用溢出属性的情况下得到解决。
GATE(Graduate Aptitude Test in Engineering) is one the most
important and in-demand entrance exam for engineering graduates
in our country. M.Tech. in Computer Science is one of the most
demanding courses at prestigious institutes like IISCs and IITs.
GATE(Graduate Aptitude Test in Engineering) is one of the ways
to get into these top institutes. Every year around 10 Lakh
candidates apply for GATE exam and very few of them manage to
ace the exam with good score. So the competition is clearly
very tough and simply preparing without any strategy will make
it difficult to land you into IISCs and IITs.
输出:
示例 2:在此代码中,使用溢出属性修复了问题。
GATE(Graduate Aptitude Test in Engineering) is one the most
important and in-demand entrance exam for engineering graduates
in our country. M.Tech. in Computer Science is one of the most
demanding courses at prestigious institutes like IISCs and IITs.
GATE(Graduate Aptitude Test in Engineering) is one of the ways
to get into these top institutes. Every year around 10 Lakh
candidates apply for GATE exam and very few of them manage to
ace the exam with good score. So the competition is clearly
very tough and simply preparing without any strategy will make
it difficult to land you into IISCs and IITs.
输出: