html - CSS clear:两者都不清除双方?
问题描述
我clear:both
想清除任何浮动元素的两侧,当我在盒子 C 上使用 clear:both 时,为什么它的右侧仍然有 D、E、F?
.bigbox {
border: 2px blue solid;
width: 80px;
height: 80px;
}
.box {
background-color: beige;
color: black;
height: 15px;
width: 15px;
border-radius: 5px;
border: 2px dodgerblue solid;
}
.float {
float: left;
}
.clearboth {
clear: both;
}
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head>
<body>
<div class="bigbox">
<div class="box float">A</div>
<div class="box float">B</div>
<div class="box float clearboth">C</div>
<div class="box float">D</div>
<div class="box float">E</div>
<div class="box float">F</div>
<div class="box float">G</div>
</div>
</body>
</html>
解决方案
clear
在一个元素上只清除它之前的浮动以文档顺序。它不会清除它之后的浮动。left 和 right 值分别表示元素之前的左浮动和右浮动的间隙。它们并不意味着在元素之前和之后清除浮动。
clearboth
您可以在要清除的 div中添加您的类。
在您的情况下,如果您想降低 D、E 和 F。将您的clearboth
课程添加到 D。
推荐阅读
- ffmpeg - 评估链式过滤器时忽略过滤器分号的 FFmpeg 结尾
- wordpress - 不显示带有“产品类别”小部件的产品
- java - 尝试在 Java 的 Switch 案例中输入,但向我展示了另一个结果。这里的具体问题是什么?
- c - STM32H743 核板,在轮询模式下一次使用 3 个 ADC(一次 1 个 ADC);不工作
- botframework - 团队中的 Microsoft Botframework V4 日历虚拟助手 Azure AD 身份验证收到错误请求
- python - 如何让敌人跟随玩家?游戏
- animation - 如何在 SwiftUI 中停止 Animation().repeatForever
- tree - 如何使用数据块构建范围树?
- python - 使用 discord.py 无法在嵌入中正常工作
- python - 数据框水平堆积条形图