【问题标题】:Changing stack order between different rows flexbox更改不同行flexbox之间的堆栈顺序
【发布时间】:2017-05-11 19:05:33
【问题描述】:

早安。我试图在 flexbox 情况下更改堆叠顺序,其中有 2 列,但第一列包含需要将第二列放在中间的位置。因此,当在移动设备上时,我需要它们的订购方式与源订购方式不同。

这个很大

col 1     col 2
----------==============
[A]         [C]
[B]

其中 A 和 B 在一列中,C 在另一列中

但在小断点上,它需要是

[A]
[C]
[B]

这可能只使用 Flexbox 吗?

所以澄清一下。 HTML结构是这样的:

row
  column
    divA
    divB

  column
    divC

Codepen example

.a { background-color: green; }
.b { background-color: red; }
.c { background-color: blue; }

.row {
  display: flex;
  flex-direction: column;
}
.column {
  flex: 1;
}

@media (min-width: 768px) {
  .row {
     flex-direction: row;
  }
}
<div class="row">
  
  <div class="column">
      <div class="a">A</div>
      <div class="b">B</div>
  </div>
  <div class="column c">C</div>
</div>

【问题讨论】:

  • 这是全页布局吗?

标签: html css flexbox


【解决方案1】:

您可以通过媒体查询和订单来实现您想要的:

.a {
  background-color: green;
  order: 1;
}

.b {
  background-color: red;
  order: 3;
}

.c {
  background-color: blue;
  order: 2;
}

.row {
  width: 100%;
  display: flex;
  flex-direction: row; 
  flex-wrap: wrap;     /* add this so you don't need the extra wrapper div */
}

.row>div {
  width: 50%; /* start off width children being 50% width */
}

@media (max-width: 768px) {
  .row>div {
     /* for small screens */
    width: 100%;
  }
}
<div class="row">
  <div class="a">A</div>
  <div class="b">B</div>
  <div class="c">C</div>
</div>

【讨论】:

  • 是什么让 A 和 B 在一个列中,而 c 在另一列中?顺便说一句,这是一个很好的答案:)...但是 c 没有拉伸到与 A 和 B 相同的高度!!
  • @Chiller 它是 flex wrap、行方向和宽度的混合,导致列效果 - 我不确定他们是否需要 c 列占据全高 - 我可以改变答案所以它没有
  • 我想我现在明白了! ...挑战将在 c 的高度。
  • @Chiller 不幸的是,这意味着在行上设置一个高度:codepen.io/anon/pen/rmdWVz
  • 很棒的解决方案@Chiller 谢谢!我可以用这个
猜你喜欢
  • 1970-01-01
  • 2020-01-13
  • 1970-01-01
  • 1970-01-01
  • 2016-04-15
  • 2022-11-17
  • 1970-01-01
  • 1970-01-01
  • 2015-02-13
相关资源
最近更新 更多