Flexbox Flashcards
Make a container use flexbox
display: flex
What does the flex-grow property do in a nutshell?
If the container is 500px wide
3 elements are 100 px wide
The flex properties decide what to do with the remaining space.
What do flex-basis, grow and shrink do?
Flex basis sets the original size of the box
auto makes it the size of the content
Flex grow defines the proportion (as a ratio) much of the remaining EMPTY space an item should take up
Flex shrink defines the proportion (as a ratio) of the remaining EXTRA space that should be cut from each item to make them fit within the window
What happens when you don’t define a flex on an item in a flex container?
flex: 0 1 auto;
The container is as wide as the content
Whats the flex grow number represent (first number)
The amount of the remaining space the element should take up. If set to 1 it will take up the rest of the space. If a decimal, a proportion of it.
If multiple all above the total remaining space, it’s the relative proportion of the remaining space between flex grow numbers.
if all containers are 1 or 2 or 3 etc. they will all take up the same amount of space.
But 1, 2, 3 means the first takes up 1/6, then next 2/6, and the last 3/6 of the total width.
0 means it’s got a width of 0 all the time
How do flex shrink and grow interact with the width property?
It depends on the basis
between 0% and 100% they take the percent of the width as the percent of the frame.
at auto it flex-basis tells the item to check for a width declaration
If some are auto and some are %
what does flex basis do?
The flex-basis is what defines the size of that item in terms of the space it leaves as available space
The initial value of this property is auto — in this case the browser looks to see if the items have a size. In the example above (three 100 pixel-wide items in a container which is 500 pixels wide), all of the items have a width of 100 pixels and so this is used as the flex-basis.
Define
flex-grow (number)
flex-shrink (number)
flex-basis (percent)
in one line
flex: 1 1 0%
Whats the flex shrink number represent (second number)
when the flex container shrinks beyond some limit, it sets the rate at which they shrink
0 means it doesn’t shrink
Which direction (x or y) is the main axis and which the cross axis?
It depends on flex-direction
row, x is main
column, y is main
What happens if you change the height of 1 flexbox on a row?
they all change height
What happens when the flex basis are larger or smaller than 100%?
Depends on the flex grow and shrink
Control the order of flex items
order: 1
numbers can be negative and decimals
The lower number goes to the left (by default)
Set a flex container direction
flex-direction: row
reverse-row
column
reverse-column
Set the wrapping of a flex container
flex-wrap: nowrap
wrap
reverse-wrap