What The Flexbox? Flashcards
Flexbox Basics
How do you start writing in Flexbox within CSS?
Simply define a container element as display: flex within your CSS - automatically any children elements will become flex items
What is the difference between display: inline-flex and display: flex?
display: inline-flex will make the container element as wide as its children need, whereas display: flex will default to 100 and have its width independent of the combined width of its children
What does the CSS property flex-direction do?
It sets the main axis, and thus, also the cross axis for flexbox.
When doing directional css - whether it is align-items or justify-content - what does it rely on in order to determine which direction to apply it?
The primary axis and the cross axis, as set by the flex-direction property.
What is the default property for flex-direction?
row
What are the four possible values for the flex-direction property?
row, column, row-reverse, column-reverse
What happens if you give flex-box items a width that exceeds the width of the screen?
It will evenly distribute the width throughout the children - or using the ‘flex’ property you can assign more or less space to some.
What do you apply the ‘flex-wrap’ property to?
The container - not the flex items
What is the default of the flex-wrap property?
nowrap
What is the difference if we set the flex-wrap property to a value or ‘wrap’?
The widths we have assigned now matter - if they are more than the width of the screen, it will output as many as can fit, and then wrap to the next line. The browser will determine how many rows to have and distribute the highet evenly between them.
What happens if we set the flex-wrap property to ‘wrap-reverse’?
The flex-items will be displayed in reverse of the cross-axis (so if set to default, it will display your last items at the top, and first items at the bottom)
Is margin part of the box-model?
No, so if you have a margin, and a width that is more than the width of the screen, it will break and either wrap or just distribute the widths evenly.
How can you get around the fact that margin is not part of the box-model?
You can set your widths using calc. For instance, something like ‘ width: calc(33.3333% - 20px) will account for a 10px margin all around, and calculate how much width to take off to allow all the items to appear on one line.
Are padding and border part of the box model?
Yes, so they will be included within whatever width you have set for an item - unlike margin.
What does the flexbox property of ‘order’ allow you to do?
With it, you can move the order of your DOM elements without actually moving them within the DOM
What is the default order for a flex-item if it isn’t set?
0 - so if you set anything to something greater than 0, it will be placed at the end of the main axis.
What’s a prime example of where you may want to use the flexbox: order property?
When you have content that needs to be re-positioned within a mobile layout - for instance, if some content needs to be moved to the footer.
What happens if we give a negative value to the order property?
This also works - just like z-index. It will move the flex item ahead of all the others to the front of the main axis.
What’s the weird gotcha of the flexbox order property?
When you go to select with your cursor, as if to copy and paste - it will still follow the order the elements were originally in - not the order they are displayed in. This will make copy and pasting a headache.