Working With Flex
Flexbox (or flex layout) is a CSS box model optimized for user interface design. The child elements of a flex container have greater “flexibility” on how it is laid out on an HTML page. This means that it provides a simpler and more powerful tool for distributing space and aligning content for complex (or simple) layouts in web apps or web pages.
Using Flexbox can get your Responsive website layout working as intended.
Below is the barebones to get Flexbox going. The example is keeping the “Mobile First” approach.
The following is a barebones example of the HTML:
1 2 3 4 5 6 |
|
First we define display: flex
to the parent element that we want to hold the
elements that will flex.
1 2 3 4 |
|
flex-direction: row
will place each child element on its own row.
For wider viewports, we will switch the elements to be in its each column.
1 2 3 4 5 |
|
For the child elements, we define a flex: auto
. flex: auto
will automatically
adjust the widths of the adjacent elements.
1 2 3 4 5 6 |
|
Full SCSS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Below you will find more Flexbox resources:
Reading
Code
Sandboxes
Technical