22
loading...
This website collects cookies to deliver better user experience
flex-direction
property which are:flex-direction: row
it is stacked to the right.flex-direction
to the red box, not the items. According to that, we are basically telling the red box to be a single row. Think of it as an excel spreadsheet. If the red box is a single row, we can only put elements to the right, like the excel spreadsheet.flex-direction: column
is basically the same, you are telling the red box to be a single column in a spreadsheet, then you can only add items to the bottom.flex-direction
. For example with the same illustration on top, when we declare flex-direction: row
, then the main axis is horizontal or to left-right.The mental model I use to remember this is, Justify Content moves around items on the main axis.
justify-content
but align-items
do not have all property from justify-content. Align items work on the cross axis. Which is the opposite of our main axis.Same with justify-content mental model, you only need to remember that Align Items work on the cross axis.
<div class='red-box'>
<div class="item">
<p>1</p>
</div>
<div class="item">
<p>2</p>
</div>
<div class="item">
<p>3</p>
</div>
<div class="item">
<p>4</p>
</div>
<div class="item">
<p>5</p>
</div>
</div>
<style>
.red-box {
width: 500px;
display: flex;
}
.item {
width: 100px;
}
</style>
Reddy: 500px
Request List:
1,2,3,4,5: 100px
Reddy: 700px
Request List:
1,3,5: 100px
2,4: 200px
Item Number = Ratio
1:2:3:4:5 = 100px:200px:100px:200px:100px
simplified,
1:2:3:4:5 = 1:2:1:2:1
flex-shrink: 0
on the .item
. Reddy will recognize the item as a VIP Member, and won't shrink it no matter what.width: 100%
basically will translate to 100% of the container which is 500px. By doing that, this means that width: 100% will get calculated in the request ratio which is 1:5:1.flex-grow: 1
, the items will not get calculated in the request ratio, but takes the rest of whatever is left.Originally posted on my personal site, find more blog posts and code snippets library I put up for easy access on my site 🚀