Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the flex order when wrapping [closed]

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.

like image 809
Arthur Avatar asked May 27 '16 17:05

Arthur


People also ask

Can we change the order of Flex items?

Flex items are displayed in the same order as they appear in the source document by default. The order property can be used to change this ordering.

How do you control a flex-wrap?

Making things wrap If you want to cause them to wrap once they become too wide you must add the flex-wrap property with a value of wrap , or use the shorthand flex-flow with values of row wrap or column wrap . Items will then wrap in the container.

How do I reverse a flex order?

default flex-direction: row; The flexbox items are ordered the same way as the text direction, along the main axis. flex-direction: row-reverse; The flexbox items are ordered the opposite way as the text direction, along the main axis.


1 Answers

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>
like image 149
Nenad Vracar Avatar answered Oct 02 '22 03:10

Nenad Vracar