html - CSS - How to stack divs by columns of 2 -


i have variable number of divs, should displayed on 2 lines, follows

[1]  [3]  [5]  [7]  [2]  [4]  [6]  ... 

i looked @ column-count property, it's not need, fixes number of columns, whereas in case should dynamic. (what need similar line-count property, doesn't seeem exist).

is there pure css solution, or should make container divs every groups of 2 vertical divs?

thanks,

edit : here simplified code of case. actually, set height property on container div, shouldn't article divs stacked @ 2 ? they're overflowing container.

<html> <head> <link rel="stylesheet" type="text/css" href="test.css"> </head> <body> <div class="container"> <div class="article">a</div> <div class="article">b</div> <div class="article">c</div> <div class="article">d</div> <div class="article">e</div> </div> </body> </html> 

and css

.article { width:50px; height:50px; border:1px gray dashed; margin:1px; }  .container { height:110px; max-height:110px; } 

however code article divs in 1 column.

you can using flexbox , flex-direction: column; doing allow have new columns once bottom of parent element reached.

here example:

*  {    box-sizing: border-box  }  .flex-parent  {    display: flex;    flex-flow: column wrap;    /* indicates, when new "column" started */    height: 200px;    align-content: flex-start;  }  .flex-parent .col  {    flex: 0 0 auto;    width: 100px;    height: 50px;    background-color: silver;    margin: 4px;  }
<div class="flex-parent">    <div class="col">1</div>    <div class="col">2</div>    <div class="col">3</div>    <div class="col">4</div>    <div class="col">5</div>    <div class="col">6</div>    <div class="col">7</div>    <div class="col">8</div>    <div class="col">10</div>    <div class="col">11</div>    <div class="col">12</div>  </div>


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -