Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"rowspan" behavior with flexbox

Tags:

css

flexbox

Given this markup :

<div class="foo">
    <div class="a"></div>
    <div class="b"></div>
    <div class="c"></div>
</div>

And CSS:

.foo {
    display: flex;
    flex-wrap: wrap;
}

.a {
    flex: none;
    width: 50%;
    height: 100px;
    background: green;
}

.b {
    flex: none;
    width: 50%;
    height: 200px;
    background: blue;
}

.c {
    flex: none;
    width: 50%;
    height: 100px;
    background: red;
}

jsFiddle

Is there a way to put the red box in the previous row stream ? I would like to avoid modifying the markup.

The idea here is that the elements should have different layouts between portrait and landscape mode, and that the only way to do it in CSS-only is to use flexbox with the order property. As far as I know, using an intermediate element would lock its children.

like image 600
Maël Nison Avatar asked Apr 06 '14 13:04

Maël Nison


People also ask

What is Flexbasis?

The flex-basis CSS property sets the initial main size of a flex item. It sets the size of the content box unless otherwise set with box-sizing .

How do you make a table responsive in Flex?

Responsive tables with flexboxOrder markup exactly how a mobile or screen reader should read it, use semantic headers and content. Abandon all concept of 'row' wrappers. Set the width of each cell as a percentage based on number of columns or rows. Auto sizing column widths is not possible.

Can I use Flexbox in table?

For modern browsers, we all can use flexbox to create responsive tables! If you want to know more about flexbox, you can always view the superb guide from CSSTricks! First, this is what we want to do: Desktop, tablet and mobile version of this table.


1 Answers

is this what you are looking for?

.foo {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  height: 200px;
}

.a, .c {
  flex: 0 0 50%;
  background: green;
}

.b {
  flex: 0 0 100%;
  order: 1;
  background: blue;
}
.c {
  background: red;
}

Quick codepen sample with -webkit- prefixes

UPDATE! Tuned pen with landscape/portrait ratios

like image 198
Veiko Jääger Avatar answered Nov 15 '22 19:11

Veiko Jääger