html - 将一个 div 一个接一个地放置
问题描述
我正在尝试一个div
接一个地垂直放置,一些 div 放在右边,另一个放在左边,比如短信。
我有这样的东西,但它没有起到作用。
有任何想法吗?
container {
margin-left: 5px;
}
right {
float: right;
width: 50%;
margin-bottom: 5px;
}
left {
float: left;
width: 50%;
margin-bottom: 5px;
}
<div class='container'>
<div class='right'>
"text to the right"
</div>
<div class='left'>
"text to the left"
</div>
<div class='right'>
"text to the right"
</div>
</div>
解决方案
修正@j08691 提到的错字并添加clear: both
到.right
and .left
。
请参阅下面的片段:
container {
margin-left: 5px;
}
.right {
clear: both;
float: right;
width: 50%;
margin-bottom: 5px;
}
.left {
clear: both;
float: left;
width: 50%;
margin-bottom: 5px;
}
<div class='container'>
<div class='right'>
"text to the right"
</div>
<div class='left'>
"text to the left"
</div>
<div class='right'>
"text to the right"
</div>
</div>
推荐阅读
- python - Popen 命令不运行集群中的代码
- javascript - 使用 ramda.js 将嵌套对象数组中的键值与标识符键匹配
- amazon-web-services - 为什么 AWS CLI list-subscriptions 命令的输出与 AWS 控制台中显示的不同?
- maven - 如何通过单个 pom.xml 创建多个程序集
- javascript - CORS 策略:请求的资源错误中不存在“Access-Control-Allow-Origin”标头
- angularjs - AngularJS基于带有单选按钮的文本字段创建过滤器作为搜索子类别
- spring - 为什么 Spring RestTemplate 在 Spring 中默认不是 Bean?
- excel - PowerShell 脚本要求输入密码并使用它来打开 excel 文件
- javascript - 从源代码显示 base64 图像 HTML
- themes - 在 Keycloak terms.ftl 中访问用户属性