【发布时间】:2023-03-16 16:25:01
【问题描述】:
我正在尝试创建一个连续有多个 3 个 div 的页面,这些 div 左右居中对齐。
我尝试使用float:left 和float:right,但效果非常糟糕。页面超级随机缩放,我希望 div 在页面缩小时变为 2 列,然后在移动设备上变为 1 列。
.container {
display: inline-block;
text-align: center;
width: 100%;
position: relative;
}
.left,
.middle,
.right {
width: 200px;
height: 200px;
background-color: red;
display: inline-block;
}
.left {
float: left;
}
.right {
float: right;
}
<div class="container">
<div class="left">
<div class="content">
</div>
</div>
<div class="middle">
<div class="content">
</div>
</div>
<div class="right">
<div class="content">
</div>
</div>
</div>
jsFiddle:https://jsfiddle.net/azizn/j4cgef5g/
【问题讨论】:
-
考虑调查媒体查询。当每行有 2 个时,第 3 个项目应该如何表现?将在 2 个框下居中?
-
你在使用吗?引导程序。框架。 ?
-
我没有使用引导程序,当它们变为 2 时,我希望它们彼此处于下方。类似于此页面的内容:indiegogo.com/partners