gpt4 book ai didi

css - Flexbox - 两个小元素紧挨着一个大元素

转载 作者:技术小花猫 更新时间:2023-10-29 11:22:50 25 4
gpt4 key购买 nike

我需要一个在移动设备上看起来像这样的布局

-----
| 1 |
-----
| 2 |
-----
| 3 |
-----

在桌面上像这样:

---------
| | 1 |
| 2 |---|
| | 3 |
| |----
| |
-----

我决定使用 flexbox,到目前为止我的代码:

<div class="row">
<div class="col-xl secound">2</div>
<div class="col-sm first">1<br>2<br>3<br>4</div>
<div class="col-xl third">3</div>
</div>

.row {
display: flex;
flex-flow: row wrap;
}

.col-sm,
.col-xl {
width: 100%;
}

.col-sm {
background: yellow;
}

.col-xl {
&.secound {
background: #ccc;
}

&.third {
background: #aaa;
}
}

@media (min-width: 700px) {
.col-sm {
width: 25%;
background: yellow;
order: 1;
}

.col-xl {
width: 75%;

&.secound {
background: #ccc;
order: 2;
}

&.third {
background: #aaa;
order: 3;
}
}
}

不幸的是,我无法滑动列“3”到“1”下。我应该怎么办?

代码笔:http://codepen.io/tomekbuszewski/pen/PbprJP?editors=1100

最佳答案

您可以尝试在桌面上使用 float,并在移动设备上使用设置了 order 的 flexbox。

jsFiddle

.item-1 {background:aqua;}
.item-2 {background:gold;}
.item-3 {background:pink;}

.row {
overflow: hidden;
}
.item {
width: 50%;
}
.item-2 {
float: left;
}
.item-1,
.item-3 {
overflow: hidden;
}
@media (max-width: 768px) {
.row {
display: flex;
flex-direction: column;
}
.item {
width: auto;
float: none;
}
.item-1 {
order: -1;
}
}
<div class="row">
<div class="item item-2">2<br><br><br></div>
<div class="item item-1">1</div>
<div class="item item-3">3</div>
</div>

关于css - Flexbox - 两个小元素紧挨着一个大元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40741002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com