0

I want (if possible) to make a css trick to create 3 columns, ascending order, from top to bottom and left to right. I would rather show with examples what I want to achieve:

For

<div class="container">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
</div>

I would like to see this order:

1 4 6
2 5 7
3

For

<div class="container">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
</div>

I would like to see this order:

1 3 5
2 4 6

For

<div class="container">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
</div>

I would like to see:

1 3 5
2 4

For

<div class="container">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
</div>

I would like to see:

1 3 4
2 

For

<div class="container">
    <div>1</div>
    <div>2</div>
    <div>3</div>
</div>

I would like to see:

1 2 3

For

<div class="container">
    <div>1</div>
    <div>2</div>
</div>

I would like to see:

1 2 

And so on. I was thinking to use flex columns but could make to match the pattern above. So I used Javascript to order the columns and achieve the desired effect. But some folks claim it could be achieved as well using CSS `flexbox.

Hairi
  • 3,318
  • 2
  • 29
  • 68
  • Can't be done using flexbox because of the way you have the gap below 5 on the first one and 3 when you only have 4. It may be possible with grid, but not sure as I haven't used it that much – Pete Apr 30 '19 at 09:21
  • you can almost have this with column: https://jsfiddle.net/ytw6mb2c/ – Temani Afif Apr 30 '19 at 09:29
  • Find similar example: https://stackoverflow.com/questions/44092529/make-grid-container-fill-columns-not-rows – Saravana Apr 30 '19 at 09:44
  • @TemaniAfif I know you can answer this question:) – Saravana Apr 30 '19 at 09:45

0 Answers0