What is flexbox?
- a layout system
- to understand it, we need to briefly jump into some web design history
- regular web elements (before flexbox) were difficult to arrange/design
- we have
- block -- most defaults, elements take the entire width and auto height
- inline -- a, spans, bold, they're meant to sit next to each other or inline. Often text elements.
- inline-block -- inline can't have margins (and vertical padding is ignored), inline block combines both and allows margin/padding
- and table -- Looks like a spreadsheet, hyper-specific designs, but really cumbersome to code
- for layouts, we've been using floats for the past 4 or so years
- show example (float something to the right side)
- there's a few issues
- we need to use clearfix so floats don't hang (since floats kind of ignore their parent containers)
- widths need to be set explicitly or they're auto (show real width of right-float example)
- flexbox turns the children of a block-like element into something that understands and fills available space
- show example
Why would we use flexbox
- so flexbox is most useful in two-dimensional layouts
- useful for when you'd like to use up the entire block, but you don't want to explicitly express all the widths
- it's a semantic replacement for floats in app-design (float still has uses)
Flexbox examples in webapp
- show header in Settings for how things were
- show header in /pages
- show page list item
Flexbox properties
- parent
- display: flex
- flex-direction: row row-reverse column column-reverse
- flex-wrap: nowrap wrap wrap-reverse
- justify-content: flex-start flex-end center space-between space-around (horizontal spacing)
- align-items: flex-start flex-end center stretch baseline
- align-content (same as align-items but handles multi-line flexbox)
- children
- order: int
- flex: grow shrink basis
- align-self: auto flex-start flex-end center baseline stretch (works like align-items but for a specific element)
Code exercise https://gist.github.com/bholtbholt/8ffcd1fe7dd44a092ad805845eb75c27