A
A
Anton2017-06-16 16:18:29
HTML
Anton, 2017-06-16 16:18:29

How to align flexbox items like in a table?

There is a three column layout built on flexbox. All columns are generated via PHP and have the following structure:

<div class="flex-container">
<div class="flex-inner"></div>
<div class="flex-inner"></div>
<div class="flex-inner"></div>
</div>

How to align flex-inner items as shown in the image without adding any parents? With a table, this is easy to do, but how to do it with flexbox without adding unnecessary elements.
8775c873d4e440d0ba8c46cc9fd17e37.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Botev, 2017-06-16
@DigitalEmotions

Styles can be written inline, or you can set blocks by class and twist-twist them as you like.
Link to the sandbox. There you can sip the window and check the rubberiness. In the example, the width and height of the container are each 100 viewport units for illustration purposes only. In your case, they may be different.
And code, in case the sandbox dies.

<div class="flex-container">
    <div class="flex-inner first"></div>
    <div class="flex-inner second"></div>
    <div class="flex-inner third"></div>
  </div>

.flex-container {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  width: 100vw;
  height: 100vh;
}
.flex-inner {
  display: flex;
}
.first {
  background-color: orange;
  width: 65%;
  height: 100%;
}

.second {
  background-color: green;
  width: 35%;
  height: 50%;
}

.third {
  background-color: yellow;
  width: 35%;
  height: 50%;
}

I highly recommend checking out this and other flexbox guides. Good to know even if you are a backender

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question