html - 包含行中的列
问题描述
我创建了三列,我想将它们包含在一行中,然后包含在一个部分中。
出于某种原因,三列不会正确包含在行内,是否有更好的方法或我在代码中遗漏的东西来纠正这个问题?
.column-1-3 {
width: 29.666%;
margin-right: 5.5%;
float: left;
}
.column-last-child {
margin-right: 0!important;
}
.section {
width: 100%;
margin: 40px 0;
padding: 40px 0;
position: relative;
}
.row {
width: 80%;
max-width: 1080px;
min-width: 414px;
margin: auto;
}
.post {
width: 100%;
height: auto;
position: relative;
background: #000;
padding: 50px;
}
.video-post {
background: #000;
height: 300px;
width: 100%
}
<div class="section">
<div class="row">
<div class="column-1-3">
<div class="video-post"></div>
</div>
<div class="column-1-3">
<div class="video-post"></div>
</div>
<div class="column-1-3 column-last-child">
<div class="video-post"></div>
</div>
</div>
</div>
解决方案
添加display: flex;
行,并float
从中删除属性column-1-3
:
.column-1-3 {
width: 30%;
}
.section {
width: 100%;
margin: 40px 0;
padding: 40px 0;
position: relative;
}
.row {
display: flex;
width: 80%;
max-width: 1080px;
min-width: 414px;
margin: auto;
justify-content: space-between;
}
.post {
width: 100%;
height: auto;
position: relative;
background: #000;
padding: 50px;
}
.video-post {
background: #000;
height: 300px;
width: 100%
}
<div class="section">
<div class="row">
<div class="column-1-3">
<div class="video-post"></div>
</div>
<div class="column-1-3">
<div class="video-post"></div>
</div>
<div class="column-1-3">
<div class="video-post"></div>
</div>
</div>
</div>
您也不需要将margin
s 设置为flex
. 只需保留width: 30%
列并justify-content: space-between;
在行上使用。
推荐阅读
- php - 无法与 PHP 数组交互
- python - 在 Dataflow 管道中写入 BigQuery 时捕获失败
- java - 错误 403 与错误 404
- javascript - PWA - 请求权限不适用于 Android Chrome
- mongodb - MongoDB中带有AND条件的SQL JOIN
- kotlin - Kotlin:withContext() 与 Async-await
- yii2 - yii2 kartik daterangepicker 单击开始日期时自动选择结束日期
- ios - Firebase 和 Swift 用户名区分大小写
- java - 访问外部文件
- android - 系统服务如何重启?