javascript - Nested flexboxes and items alignment -
i'm trying create own small grid system based on css3 flex display. have following classes:
- a
gridclass, flex container flex-direction set column. - a
rowclass, flex container flex-direction set row. - set of
columnclasses of different flex-basis sizes.
what want able align each row left/center/right setting self-align property of row element. however, whenever try it, things seem go bad.
here plunker demonstrate it: http://plnkr.co/edit/mhos7u28gcbjupvi7ikj?p=preview
html
<!-- first row --> <div class="row align-end"> <!-- try remove 'align-end' here --> <div class="column-1"> <div class="item">1</div> </div> <div class="column-1"> <div class="item">2</div> </div> </div> <!-- second row --> <div class="row"> <div class="column-1"> <div class="item">3</div> </div> <div class="column-2"> <div class="item">4</div> </div> </div> </div> css
* { box-sizing: border-box; } .grid { display: flex; flex-direction: column; } .row { display: flex; flex-direction: row; } .column-1 { flex-basis: 33.33%; padding: 10px; } .column-2 { flex-basis: 66.67%; padding: 10px; } .column-3 { flex-basis: 100%; padding: 10px; } .align-start { align-self: flex-start; } .align-center { align-self: center; } .align-end { align-self: flex-end; } .item { background-color: lightblue; font-family: "arial"; text-align: center; padding: 4px; } as can see, in plunker set grid 2 rows, 2 columns in each row. 2 columns in first row have width of 33.33% (flex-basis). in second row, first column's width 66.67% , second column 33.33%. now, since first row has unused space, want try align right (for whatever reason). therefore, add div represents first row class align-end, adds property align-self: flex-end; element. can see, doing first row looks bad, both columns aligned right, width totally corrupted (you can try , remove class 'align-end' first row, , things normal).
what missing? why row doesn't align correctly right?
thanks, roy.
the property controls how children aligned along main axis justify-content
.align-end { justify-content: flex-end; }
Comments
Post a Comment