Flexbox Flashcards

1
Q

What is flexbox’s full name?

A

The Flexible Box Module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Flexbox is a one-dimensional layout model, what does this mean?

A

It means that flexbox deals with layout in one dimension at a time — either as a row or as a column.

This can be contrasted with the two-dimensional model of CSS Grid Layout, which controls columns and rows together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What defines the main axis in flexbox?

A

The flex-direction property.

flex-direction: row;
The main-axis is horizontal.

flex-direction: column;
The main-axis is vertical.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Flex-direction has 4 possible values, what are they?

A

row
reverse-row
column
reverse-column

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When first creating a flex container how will the contained flex items behave .

A

Items display in a row (the flex-direction property’s default is row).

The items start from the start edge of the main axis.

The items do not stretch on the main dimension, but can shrink.

The items will stretch to fill the size of the cross axis.

The flex-basis property is set to auto.

The flex-wrap property is set to nowrap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you enable wrapping behaviour with flex-box?

A

With the flex-wrap property set to wrap

.container {
display: flex;
flex-wrap: wrap;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the flex-flow property?

A

A property that combines the two properties flex-direction and flex-wrap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What three properties can be used on flex-items ?

A

flex-grow
flex-shrink
flex-basis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is available space in relation to flex-box?

A

The space in a container that the children of the container don’t take up, leftover space. This available space is important to aligning items and flex-grow / flex-shrink.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of flex-basis?

A

Flex-basis is a property of flex children.
It’s initial value is auto which means it uses the size of the child element as the flex-basis. If the child doesn’t have a size it uses the size of the child elements content as the flex-basis.

If an element has a flex-basis of 100px it will grow and shrink from 100px if rules to grow and shrink are added.

So if flex-wrap is wrap on the flex container and flex-basis is 100px and flex grow is 1 on flex children then the children will grow when they have available space and wrap when they run out of space. They will not shrink below 100px.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the flex shorthand?

A

It’s rule that allows you to set flex-grow, flex-shrink, flex-basis all at once!

flex: 1 1 100px;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the default for flex-grow?

A

flex grow defaults to 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the default for flex-shrink?

A

flex-shrink defaults to 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If you have a flex column container and give one child of this container a fixed height such as 200px, and the other a flex-grow of 1. Will the fixed height child be 200px high?

A

No not necessarily as the default for flex-shrink is 1 meaning the fixed element may shrink.
To solve this add flex-shrink:0 to the fixed height child.

Shrinking only happens if all available space is taken up in the container. This means sometimes the fixed element might not shrink depending on the amount of available space.

BAD
In a less flexbox way you could add min:height: 200px to the child element;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

If you have a flex column container and give one child of this container a fixed height such as 200px, and the other a flex-grow of 1. Will the fixed height child be 200px high?

A

No not necessarily as the default for flex-shrink is 1 meaning the fixed element may shrink.
To solve this add flex-shrink:0 to the fixed height child.

Shrinking only happens if all available space is taken up in the container. This means sometimes the fixed element might not shrink depending on the amount of available space.

BAD
In a less flexbox way you could add min:height: 200px to the child element;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does flex: number equate to?

A

It is interpreted as flex: number 1 0;
flex-shrink value is assumed to be 1
flex-basis value is assumed to be 0.

17
Q

How will the children of this container behave and why?

.container{
    display: flex;
    flex-direction: row;
    height: 100vh;
    justify-content: space-around;
    align-items: center;
}
A

The children elements will be spaced across the main axis because of justify-content: space-around. Normally the children elements would be the full size of the cross axis but the property align-items: center changes this. This makes sense as you can’t center an element that covers the full size of its container.