Skip to content

Instantly share code, notes, and snippets.

@qmmr
Created February 2, 2014 18:21
Show Gist options
  • Save qmmr/8772533 to your computer and use it in GitHub Desktop.
Save qmmr/8772533 to your computer and use it in GitHub Desktop.
Flexbox - aligning multiple lines.
%header
%h1 Flexbox - aligning multiple lines
%article
%section.flex-container
.box
%h3 One
.box
%h3 Two
.box
%h3 Three
.box
%h3 Four
.box
%h3 Five
.box
%h3 Six
.box
%h3 Seven
.box
%h3 Eight
.box
%h3 Nine
// ----
// Sass (v3.3.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
@import "compass";
@import url(http://fonts.googleapis.com/css?family=Audiowide);
// Documentation about Flex
// http://www.w3.org/TR/css3-flexbox/
$colors: (chartreuse, royalblue, plum, teal, lightsteelblue, sienna, maroon, lime, cornflowerblue, darkviolet, dodgerblue);
@for $n from 1 through length($colors) {
.box:nth-child(#{$n}) {
background-color: nth($colors, $n);
}
}
body {
width: 80%;
margin: 0 auto;
padding: 2%;
line-height: 1.6;
}
.flex-container {
@include display-flex(flex);
border: 1px solid #333;
margin: 0 auto;
width: 50%;
height: 600px;
// flex-start, flex-end, space-between, space-around
@include justify-content(space-around);
// flex-flow is a shorthand for flex-direction & flex-wrap
@include flex-flow(row wrap);
// flex-start, flex-end, center, space-between, space-around, stretch
@include align-content(flex-end);
}
.box {
font-family: 'Audiowide', cursive;
font-size: 1.8em;
line-height: 1;
margin: 0 5px;
padding: 10px 20px;
text-align: center;
}
@import url(http://fonts.googleapis.com/css?family=Audiowide);
.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;
}
.box:nth-child(5) {
background-color: lightsteelblue;
}
.box:nth-child(6) {
background-color: sienna;
}
.box:nth-child(7) {
background-color: maroon;
}
.box:nth-child(8) {
background-color: lime;
}
.box:nth-child(9) {
background-color: cornflowerblue;
}
.box:nth-child(10) {
background-color: darkviolet;
}
.box:nth-child(11) {
background-color: dodgerblue;
}
body {
width: 80%;
margin: 0 auto;
padding: 2%;
line-height: 1.6;
}
.flex-container {
display: -webkit-flex;
display: flex;
border: 1px solid #333;
margin: 0 auto;
width: 50%;
height: 600px;
-webkit-justify-content: space-around;
justify-content: space-around;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-align-content: flex-end;
align-content: flex-end;
}
.box {
font-family: 'Audiowide', cursive;
font-size: 1.8em;
line-height: 1;
margin: 0 5px;
padding: 10px 20px;
text-align: center;
}
<header>
<h1>Flexbox - aligning multiple lines</h1>
</header>
<article>
<section class='flex-container'>
<div class='box'>
<h3>One</h3>
</div>
<div class='box'>
<h3>Two</h3>
</div>
<div class='box'>
<h3>Three</h3>
</div>
<div class='box'>
<h3>Four</h3>
</div>
<div class='box'>
<h3>Five</h3>
</div>
<div class='box'>
<h3>Six</h3>
</div>
<div class='box'>
<h3>Seven</h3>
</div>
<div class='box'>
<h3>Eight</h3>
</div>
<div class='box'>
<h3>Nine</h3>
</div>
</section>
</article>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment