How to change the flex order when wrapping [closed]

自古美人都是妖i 提交于 2019-11-29 17:31:13

问题


I would like to achieve something that renders like this depending on the screen size:

+---------------------------+
|  A  |       B       |  C  |
+---------------------------+

+---------------+
|   A   |   C   |
|       B       |
+---------------+

if all size are fixed, i can manage using the flex order property but the size of my C container is not fixed and so I can't use a static media query.

Is there a way to achieve this?

Edit: I managed a good enough approximation: In a media query selecting all screens that might need wrapping, I change the order of the B container to something big, and at the same time, I set its min-width to 100% which forces the wrap.


回答1:


You can make b element full width with flex: 0 0 100% and change order to order: 2 with media queries DEMO

* {
  box-sizing: border-box;
}
body, html {
  margin: 0;
  padding: 0;
}
.content {
  display: flex;
  flex-wrap: wrap;
}
.b {
  background: lightblue;
}
.a, .b, .c {
  border: 1px solid black;
  flex: 1;
  padding: 10px;
}
@media(max-width: 768px) {
  .b {
    flex: 0 0 100%;
    order: 2;
  }
}
<div class="content">
  <div class="a">A</div>
  <div class="b">B</div>
  <div class="c">C</div>
</div>


来源:https://stackoverflow.com/questions/37489270/how-to-change-the-flex-order-when-wrapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!