Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Why Use Flexbox?

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for Jay Shenk Jay Shenk
February 01, 2017

Why Use Flexbox?

Examples from the talk on Codepen: http://codepen.io/collection/DEgbqk/

Additional resources for learning Flexbox: https://gist.github.com/jayshenk/ae9a5d7641533f3fd683a529a7fe020b

Avatar for Jay Shenk

Jay Shenk

February 01, 2017
Tweet

More Decks by Jay Shenk

Other Decks in Programming

Transcript

  1. Pain Points • Floats weren't designed for layout (just content

    wrapping around an image) • Floats have to be cleared • Responsive design often requires many media queries • Whitespace between inline elements • Vertical alignment is problematic
  2. body { position: relative; } div { position: absolute; top:

    50%; left: 50%; transform: translate(-50%, -50%); }
  3. nav div { width: 49%; } .left { float: left;

    } .right { float: right; } nav div a { display: inline-block; }
  4. nav { display: flex; justify-content: space-between; align-items: stretch; /* Default

    */ } nav div { flex: 0 0 49%; display: flex; } nav div a { display: flex; align-items: center; }