Loading
ehayman
This is a live streamed presentation. You will automatically follow the presenter and see the slide they're currently on.
Emily Hayman @eehayman 2016 CSS Conf
display: flex;
flex-direction: row || column;
flex-wrap: nowrap || wrap;
justify-content (main-axis): flex-start, flex-end, space-between, space-around, center
align-items (cross-axis): center, flex-start, flex-end, baseline, stretch
display: flex;
justify-content: space-between;
align-items: center;
clear: both;
> .logo float: left;
> .navigation float: right; margin-top: magic hard-coded number;
vs.
flex-grow: element size relative to its siblings
flex-basis: specify initial main size
display: flex;
justify-content: space-between;
align-items: center;
Main container
Search field container
display: flex;
//align-items: stretch; default!
Search input
flex-grow: 1;
.container {
display: flex;
}
.container > div {
flex-grow: 1;
flex-basis: 0;
}
.container {
display: flex;
}
.container > div {
flex-grow: 1;
flex-basis: 0;
margin-left: 15px;
margin-right: 15px;
}
.container > div:first-child {
margin-left: 0;
}
.container > div:last-child {
margin-right: 0;
}
.container {
display: flex;
}
.container > div {
flex-grow: 1;
flex-basis: 0;
margin-left: 15px;
margin-right: 15px;
}
.container > div:first-child {
margin-left: 0;
}
.container > div:last-child {
margin-right: 0;
}
@media (max-width: 600px) {
.container {
flex-direction: column;
}
.container > div {
flex-basis: auto;
margin-left: 0;
margin-right: 0;
}
.container > div + div {
margin-top: 30px;
}
}
@mixin flexbox-equal-col($padding: 20px, $whitespace: margin, $element: "div", $column-breakpoint: 0) {
display: flex;
> #{$element} {
flex-basis: 0;
flex-grow: 1;
#{$whitespace}-left: (1/2) * $padding;
#{$whitespace}-right: (1/2) * $padding;
&:first-child {
#{$whitespace}-left: 0;
}
&:last-child {
#{$whitespace}-right: 0;
}
}
@if ($column-breakpoint != 0) {
@media (max-width:$column-breakpoint) {
flex-direction: column;
> #{$element} {
flex-basis: auto;
#{$whitespace}-left: 0;
#{$whitespace}-right: 0;
+ #{$element} {
#{$whitespace}-top: $column-padding;
}
}
}
}
}
.container {
@include flexbox-equal-col($padding: 30px, $column-breakpoint: 600px);
}
1 fixed width - the other takes up remaining space
@mixin flexbox-two-col-fixed($fixed-col: left, $fixed-col-width: 250px);
@mixin flexbox-two-col-fixed($fixed-col, $fixed-col-width, $element: "div") {
display: flex;
> #{$element} {
&:first-child {
@if $fixed-col == left {
flex-basis: $fixed-col-width;
}
@if $fixed-col == right {
flex-grow: 1;
flex-basis: 0;
}
}
&:last-child {
@if $fixed-col == left {
flex-grow: 1;
flex-basis: 0;
}
@if $fixed-col == right {
flex-basis: $fixed-col-width;
}
}
}
}
1 content-based width; other takes up remaining space
@include flexbox-two-col-flexible($fixed-col: left, $padding: 30px);
@mixin flexbox-two-col-flexible($fixed-col, $padding: $column-gutter, $element: "div") {
display: flex;
> #{$element} {
&:first-child {
@if $fixed-col == left {
margin-right: $padding;
}
@if $fixed-col == right {
flex-grow: 1;
flex-basis: 0;
}
}
&:last-child {
@if $fixed-col == left {
flex-grow: 1;
flex-basis: 0;
}
@if $fixed-col == right {
margin-left: $padding;
}
}
}
}
Both percentage-based widths
@include flexbox-two-col-fluid($first-col-width: 55%, $padding: 60px);
@mixin flexbox-two-col-fluid($first-col-width, $padding: $column-gutter, $element: "div") {
display: flex;
> #{$element} {
&:first-child {
flex-basis: $first-col-width;
margin-left: 0;
margin-right: $padding / 2;
}
&:last-child {
flex-basis: (100% - $first-col-width);
margin-right: 0;
margin-left: $padding / 2;
}
}
}
@include flexbox-grid($col-num: 3);
@mixin flexbox-grid($col-num, $element: "div", $reverse: false) {
display: flex;
@if ($reverse==false) {
flex-wrap: wrap;
}
@if ($reverse==true) {
flex-wrap: wrap-reverse;
}
> #{$element} {
flex-basis: 100% / $col-num;
}
}
.outer-container {
@include flexbox-two-col-fluid($first-col-width: 75%, $padding: 30px);
}
.left-column {
@include flexbox-equal-col();
}
.right-column {
display: flex;
flex-direction: column;
> div {
flex-grow: 1;
}
}
.item {
display: flex;
flex-direction: column;
justify-content: space-between;
}