Skip to content

Instantly share code, notes, and snippets.

@qmmr
Created February 2, 2014 15:35
Show Gist options
  • Save qmmr/8770082 to your computer and use it in GitHub Desktop.
Save qmmr/8770082 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
%header
%h1 Flexbox - main axis alignment
%article
%section.flex-container
.box.flex1
%h3 One
.box.flex1
%h3 Two
.box.flex2
%h3 Three
.box.flex1
%h3 Four
%section.flex-container.column
.box.flex1
%h3 One
.box.flex1
%h3 Two
.box.flex2
%h3 Three
.box.flex1
%h3 Four
%h1 Flexbox - cross axis alignment
%section.flex-container.cross-axis
.box.flex1
%h3 One
.box.flex1
%h3 Two
.box.flex2
%h3 Three
.box.flex1
%h3 Four
// ----
// Sass (v3.3.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
@import "compass";
// Documentation about Flex
// http://www.w3.org/TR/css3-flexbox/
$colors: (chartreuse, royalblue, plum, teal, lightsteelblue, sienna, maroon);
body {
width: 80%;
margin: 0 auto;
padding: 2%;
line-height: 1.6;
}
.flex-container {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
margin: 1em 0;
border: 1px solid #333;
// flex-start, flex-end, space-between, space-around
@include justify-content(space-between);
// flex-flow is a shorthand for flex-direction & flex-wrap
&.row {
@include flex-flow(row);
}
&.column {
@include flex-flow(column);
height: 500px;
}
&.cross-axis {
height: 200px;
// default stretch
// flex-start, flex-end, stretch, baseline
@include align-items(baseline);
}
}
.box {
text-align: center;
}
@for $n from 1 through 4 {
.box:nth-child(#{$n}) {
background-color: nth($colors, $n);
}
}
.flex1 {
width: 100px;
.column & {
width: 100%;
}
}
.flex2 {
width: 200px;
.column & {
width: 100%;
}
.cross-axis & {
margin-top: 20px;
height: 100px;
}
}
body {
width: 80%;
margin: 0 auto;
padding: 2%;
line-height: 1.6;
}
.flex-container {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
margin: 1em 0;
border: 1px solid #333;
-webkit-justify-content: space-between;
justify-content: space-between;
}
.flex-container.row {
-webkit-flex-flow: row;
flex-flow: row;
}
.flex-container.column {
-webkit-flex-flow: column;
flex-flow: column;
height: 500px;
}
.flex-container.cross-axis {
height: 200px;
-webkit-align-items: baseline;
align-items: baseline;
}
.box {
text-align: center;
}
.box:nth-child(1) {
background-color: chartreuse;
}
.box:nth-child(2) {
background-color: royalblue;
}
.box:nth-child(3) {
background-color: plum;
}
.box:nth-child(4) {
background-color: teal;
}
.flex1 {
width: 100px;
}
.column .flex1 {
width: 100%;
}
.flex2 {
width: 200px;
}
.column .flex2 {
width: 100%;
}
.cross-axis .flex2 {
margin-top: 20px;
height: 100px;
}
<header>
<h1>Flexbox - main axis alignment</h1>
</header>
<article>
<section class='flex-container'>
<div class='box flex1'>
<h3>One</h3>
</div>
<div class='box flex1'>
<h3>Two</h3>
</div>
<div class='box flex2'>
<h3>Three</h3>
</div>
<div class='box flex1'>
<h3>Four</h3>
</div>
</section>
<section class='flex-container column'>
<div class='box flex1'>
<h3>One</h3>
</div>
<div class='box flex1'>
<h3>Two</h3>
</div>
<div class='box flex2'>
<h3>Three</h3>
</div>
<div class='box flex1'>
<h3>Four</h3>
</div>
</section>
<h1>Flexbox - cross axis alignment</h1>
<section class='flex-container cross-axis'>
<div class='box flex1'>
<h3>One</h3>
</div>
<div class='box flex1'>
<h3>Two</h3>
</div>
<div class='box flex2'>
<h3>Three</h3>
</div>
<div class='box flex1'>
<h3>Four</h3>
</div>
</section>
</article>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment