html - 如何停止 div 的重叠?
问题描述
当我为容器设置浮动到右侧时,这种重叠发生,这是什么原因如何避免它?我希望黄色 div 低于红色 div,红色 div 应该在右边...
.container {
float: right;
height: 150px;
margin: 10px;
width: 50%;
display: flex;
flex-direction: row;
/* flex-wrap: wrap; */
justify-content: center;
align-items: center;
background-color: yellow;
}
<div class="container"></div>
<div style="display: block; margin: auto; background-color: red; height: 200px; width: 100%;"></div>
解决方案
使用红色规则clear: both
。 div
这是一个关键字,指示元素向下浮动以清除左右浮动。
.container {
float: right;
height: 150px;
margin: 10px;
width: 50%;
display: flex;
flex-direction: row;
/* flex-wrap: wrap; */
justify-content: center;
align-items: center;
background-color: yellow;
}
<div class="container"></div>
<div style="display: block; margin: auto; background-color: red; height: 200px; width: 100%; clear: both;"></div>
推荐阅读
- azure-devops - 在 Azure DevOps 发布管道阶段处理多个服务器
- excel - excel:错误1004。参考无效不知道为什么
- powershell - 如何通过格式化将powershell脚本输出发送到打印机?
- json - 使用 create-react-app 并且我无法解析简单的 JSON 文件
- javascript - Javascript 输出没有改变?
- reactjs - 如何在 react.js 中更改组件背景颜色更改状态?
- operating-system - 为什么 32 位操作系统有 4 GB RAM 的限制?
- button - 带有按钮的 ZStack 中的可点击图像
- rest - Tuple.of (vert.x pgclient) 中的数组
- http - 使用带有两因素身份验证的 HTTP GET 方法