Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules"
We are here for you!
Every question is important
Help each other
Have fun
Introductions
Tell us about yourself.
Who are you?
What do you hope to get out of the class?
What is your favorite vacation spot and why?
What we will cover
What is the Flexible Box Model?
How to decide when to use Flexbox
Broswer support and fallbacks
Flexbox properties and what they do
What to expect
Flexbox is a new way of thinking about layouts - this takes time and practice
We will cover all the flexbox properties and also experiment on a "real" website
What Is Flexbox?
"The CSS3 Flexible Box, or flexbox, is a layout mode providing for the arrangement of elements on a page such that the elements behave predictably when the page layout must accommodate different screen sizes and different display devices."
- MDN (Mozilla Developer Network)
Flexbox is a CSS layout mode
Block layout: for stacked elements
Inline layout: for text
Table layout: for (you guessed it) tables
Positioned layout: for elements without much interaction with other elements
Flexbox layout: designed for coding responsive elements that can be resized smoothly
Floats
...were originally meant to float text around an image.
...that's it.
Why we love Flexbox
Can replace floats to align elements smoothly
Automatic distribution of extra space
Vertical centering!!
Less code! More efficiency and less calculations of paddings, margins, widths
Drag the 'exercise' folder into your text editor and complete the following exercises:
Exercise 1: Create a horizontal navigation with all links at the top right of the page.
Bonus: Create a media query (min-width: 320px) so the navigation is stacked and center aligned on mobile.
Exercise 2: Center the headline horizontally and vertically in the hero image. Bonus: Add a call-to-action button (Read More) centered under the headline.
Let's Develop It
What about Flex Items?
Now, we'll look at properties you can apply to individual flex items to override the flex properties applied to the parent element.
Order:
Controls the order in which the items appear
Does NOT change the source order
All items default to order: 0
value: (any positive or negative integer)
.item1 {
order: 2;
}
.item2 {
order: -4;
}
Align-self:
Overrides the align-items property set on the flexbox container
Setting a margin: auto on a flex item can be used to position the flex item using the available extra space.
.item2 {
margin-left: auto;
}
Auto Margins and Flexbox
.item1 {
margin-left: auto;
}
Let's Develop It
Exercise 3: Change the About section with the image aligned to the right of the text. Bonus: Change the order of the About section to have the picture stack on top of the text in smaller devices
Flexibility
"The defining aspect of flex layout is the ability to make the flex items “flex”, altering their width/height to fill the available space in the main dimension. A flex container distributes free space to its items proportional to their flex grow factor, or shrinks them to prevent overflow proportional to their flex shrink factor."
- W3C
Flex Shorthand
Recommended for setting all of the flex properties