Flexbox patterns
Homework
- Review
- Read: Designing Card-Based User Interfaces
- Watch: Flexbox design patterns you can use in your projects by Kevin Powell. This one of Kevin’s latest video on Flexbox.
- Cards
- MDN: CSS Layout cookbook
- MDN: Cards
- CSS Grid
- Read: Grid by Example
- Reference:
- Watch the following videos on Grid by Example:
- Game: CSS Grid Garden
- Fast Layouts
- Watch: Build a Classic Layout FAST in CSS Grid by Miriam Suzanne
- Watch: Incredibly Easy Layouts with CSS Grid by Jenn Simmons
- Watch: Using Flexbox + CSS Grid Together: Easy Gallery Layout by Jenn Simmons
Morning reflection
Housekeeping
- Dailies Feedback
- selectors in
@media
blocks - pruning and optimizing code
- The Coding Lifecycle
- Understand the problem
- Plan it out
- Brute force a solution
- Walk-through
- Optimize
- Clean-up and prep
- selectors in
- Schedule changes
- Assignment due dates
- Pushed to Monday: Hero sections
- Friday: ???
- Saturday plans?
Lecture/Live code
Learning Objectives
- Demonstrate the relationship between
flex-grow
,flex-shrink
andflex-basis
. - Understand the default settings for flex items.
- Understand common shorthand declarations for
flex
. - Explore common Flex layout patterns.
Terms
- flex-basis
- The optimum size of a Flex item along the main axis.
auto
: uses the size of its content
- flex-grow
- If there is extra space in the container, does the item grow?
0
: no;1
: yes;<number>
: the item takes its share (of the containerflex-grow
total) of extra space.
- flex-shrink
- If there isn’t enough space in the container, does the item shrink?
0
: no;1
: yes;<number>
: the item gives its share (of the containerflex-shrink
total) of needed space.
Materials
See the Pen Flexbox patterns by Tony Grimes (@acidtone) on CodePen.
- Gist: Default item settings and defaults
- Gist: Even Columns
- Gist: Grid-ish
- Gist: Content/Sidebar
Key Takeaways
flex-grow
andflex-shrink
are relative toflex-basis
.flex-basis: auto
defaults to the content size.flex-basis
is overridden by:- row:
width
,min-width
andmax-width
- column:
height
,min-height
andmax-height
- row:
- It’s best practice to declare the size of an item “the Flex Way” and use
flex-basis
instead ofwidth
orheight
. min-width
/min-height
andmax-width
/max-height
are excellent ways to customize common patterns for your needs, :- applied directly to a flex item, or
- applied to an flex item’s content
WBDV Library refactor
Session Goals
Move side content to a responsive sidebar:
- Understand the problem
- Plan it out
- Brute force a solution
Open lab-time
- Start with the default flex shortcuts.
Tony’s goals
- Assignment 3 first draft
- Deploy WBDV v0.2
- notices
- page nav
- update media query primary nav
Activities
1. MDN: Test your skills
2. Pattern recognition
- Re-imagine a section of a personal project, assignment, etc in terms of Flexbox layout.
- Choose one of the patterns covered today, copy the gist to your own project/codepen/in-class.
- Using your new knowledge of
flex-basis
,flex-grow
andflex-shink
customize the pattern to fit your layout requirements.
Dailies
- Submit today’s Codepen/repo/gist to the Dailies section (in Assessments) in Brightspace.