html - Flex items in a row rendering at different widths -
i created 3 boxes using css flexbox in html chrome rendering boxes different sizes.
drag border of browser make view smaller.
thanks help!
codepen: https://codepen.io/labanino/pen/rganlp
body { font-family: arial; font-size: 2rem; text-transform: uppercase; } .flex { height: 200px; display: flex; flex-direction: row; } .flex>section { flex: 1 1 auto; display: flex; justify-content: center; flex-direction: column; text-align: center; } .flex>section:nth-child(1) { background: brown; margin-right: 20px; border: 1px solid #999; } .flex>section:nth-child(2) { background: pink; margin-right: 20px; border: 1px solid #999; } .flex>section:nth-child(3) { background: green; margin-right: 0; border: 1px solid #999; }
<div class="flex"> <section>brown</section> <section>pink</section> <section>green</section> </div>
don't use auto
in flex property items. use 100%, , adapt width in flex box, , adjusts number of elements add (in case want add more 3).
.flex > section { flex: 1 1 100%; display: flex; justify-content: center; flex-direction: column; text-align: center; }
the reason they're different sizes because when use auto
, bases width on content of box. that's why middle 1 isn't wide, because word 'pink' takes less space 'green'.
Comments
Post a Comment