Skip to content

Instantly share code, notes, and snippets.

@MikeFielden
Created July 12, 2012 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeFielden/3099583 to your computer and use it in GitHub Desktop.
Save MikeFielden/3099583 to your computer and use it in GitHub Desktop.
A web page created at CodePen.io
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>"Holy Grail" layout with flex box Chrome 22 recommended &middot; CodePen</title>
<!--
Copyright (c) 2012 Mike Fielden, http://codepen.io/MikeFielden
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<link rel="stylesheet" href="http://codepen.io/stylesheets/css/normalize.css">
<style>
@font-face {
font-family: 'Muli';
font-style: normal;
font-weight: 400;
src: local("Muli"), url(http://themes.googleusercontent.com/static/fonts/muli/v4/minRpKQdEvXRRS8oAbAtWvesZW2xOQ-xsNqO47m55DA.woff) format("woff");
}
html, body {
height: 100%;
box-sizing: border-box;
}
body {
font-family: 'Muli', Arial;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
-webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
-o-flex-direction: column;
flex-direction: column;
-webkit-justify-content: center;
-moz-justify-content: center;
-ms-justify-content: center;
-o-justify-content: center;
justify-content: center;
margin: 0 2em;
-webkit-transition: all 500ms ease-in-out;
-moz-transition: all 500ms ease-in-out;
-o-transition: all 500ms ease-in-out;
transition: all 500ms ease-in-out;
}
#mainContent {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
-o-flex: 1;
flex: 1;
max-height: 500px;
}
#mainContent > * {
border: 1px solid #ccc;
padding: .25em;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
-o-border-radius: 10px;
border-radius: 10px;
}
#mainContent > article {
-webkit-flex: 1 0 0px;
-moz-flex: 1 0 0px;
-ms-flex: 1 0 0px;
-o-flex: 1 0 0px;
flex: 1 0 0px;
-webkit-order: 2;
-moz-order: 2;
-ms-order: 2;
-o-order: 2;
order: 2;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
-o-align-items: center;
align-items: center;
-webkit-justify-content: center;
-moz-justify-content: center;
-ms-justify-content: center;
-o-justify-content: center;
justify-content: center;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
margin: 0 10px;
text-align: center;
}
#mainContent > section {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
-webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
-o-flex-direction: column;
flex-direction: column;
background: #eee;
width: 200px;
-webkit-order: 0;
-moz-order: 0;
-ms-order: 0;
-o-order: 0;
order: 0;
-webkit-flex: none;
-moz-flex: none;
-ms-flex: none;
-o-flex: none;
flex: none;
}
#mainContent > section > div {
border: 1px solid #cccccc;
padding: 0.25em;
margin: 0.25em;
background: white;
text-align: center;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
-o-flex: 1;
flex: 1;
-webkit-justify-content: center;
-moz-justify-content: center;
-ms-justify-content: center;
-o-justify-content: center;
justify-content: center;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
-o-align-items: center;
align-items: center;
-webkit-transition: -webkit-flex 1500ms cubic-bezier(0.17, 0.67, 0, 1.45);
}
#mainContent > section > div:hover {
-webkit-flex: 4;
-moz-flex: 4;
-ms-flex: 4;
-o-flex: 4;
flex: 4;
}
#mainContent > section > div:first-child {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
#mainContent > section > div:last-child {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
nav {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
-webkit-justify-content: space-between;
-moz-justify-content: space-between;
-ms-justify-content: space-between;
-o-justify-content: space-between;
justify-content: space-between;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
-o-align-items: center;
align-items: center;
-webkit-flex: none;
-moz-flex: none;
-ms-flex: none;
-o-flex: none;
flex: none;
margin-bottom: 10px;
}
nav a {
padding: 15px;
background: -webkit-linear-gradient(top, navy 50%, black) no-repeat 50% 100%, navy;
color: white;
display: block;
margin: auto 10px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
text-decoration: none;
-webkit-transition: background-size 100ms ease-in-out;
-moz-transition: background-size 100ms ease-in-out;
-o-transition: background-size 100ms ease-in-out;
transition: background-size 100ms ease-in-out;
-webkit-transition: font-size 100ms ease-in-out, 500ms;
-moz-transition: font-size 100ms ease-in-out, 500ms;
-o-transition: font-size 100ms ease-in-out, 500ms;
transition: font-size 100ms ease-in-out, 500ms;
background-size: 100% 0;
text-align: center;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
-o-flex: 1;
flex: 1;
}
nav a:first-child {
margin-left: 0;
}
nav a:last-child {
margin-right: 0;
}
nav a:hover {
background-size: 100% 100%;
}
header,
footer {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
-webkit-justify-content: flex-start;
-moz-justify-content: flex-start;
-ms-justify-content: flex-start;
-o-justify-content: flex-start;
justify-content: flex-start;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
-o-align-items: center;
align-items: center;
-webkit-flex: 0 0 20px;
-moz-flex: 0 0 20px;
-ms-flex: 0 0 20px;
-o-flex: 0 0 20px;
flex: 0 0 20px;
background: #eee;
padding: 1em;
margin: 10px 0;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
-o-border-radius: 10px;
border-radius: 10px;
color: rgba(0, 0, 0, 0.6);
text-shadow: 0 1px rgba(255, 255, 255, 0.75);
}
footer {
-webkit-justify-content: flex-end;
-moz-justify-content: flex-end;
-ms-justify-content: flex-end;
-o-justify-content: flex-end;
justify-content: flex-end;
}
@media all and (max-width: 600px) {
body {
margin: 0 10px;
-webkit-justify-content: flex-start;
-moz-justify-content: flex-start;
-ms-justify-content: flex-start;
-o-justify-content: flex-start;
justify-content: flex-start;
}
#mainContent {
-webkit-flex-flow: column;
}
#mainContent > article {
margin: 0;
}
#mainContent > section {
margin: 10px auto;
}
#mainContent > section > div {
-webkit-flex: 1 0 auto;
-moz-flex: 1 0 auto;
-ms-flex: 1 0 auto;
-o-flex: 1 0 auto;
flex: 1 0 auto;
}
#mainContent > article,
#mainContent > section,
nav {
-webkit-order: 0;
-moz-order: 0;
-ms-order: 0;
-o-order: 0;
order: 0;
width: auto;
}
nav {
font-size: 60%;
}
}
</style>
<style>
#codepen-footer, #codepen-footer * {
-webkit-box-sizing: border-box !important;
-moz-box-sizing: border-box !important;
box-sizing: border-box !important;
}
#codepen-footer {
display: block !important;
position: fixed !important;
bottom: 0 !important;
left: 0 !important;
width: 100% !important;
padding: 0 10px !important;
margin: 0 !important;
height: 30px !important;
line-height: 30px !important;
font-size: 12px !important;
color: #eeeeee !important;
background-color: #505050 !important;
text-align: left !important;
background: -webkit-linear-gradient(top, #505050, #383838) !important;
background: -moz-linear-gradient(top, #505050, #383838) !important;
background: -ms-linear-gradient(top, #505050, #383838) !important;
background: -o-linear-gradient(top, #505050, #383838) !important;
border-top: 1px solid black !important;
border-bottom: 1px solid black !important;
border-radius: 0 !important;
border-image: none !important;
box-shadow: inset 0 1px 0 #6e6e6e, 0 2px 2px rgba(0, 0, 0, 0.4) !important;
z-index: 300 !important;
font-family: "Lucida Grande", "Lucida Sans Unicode", Tahoma, sans-serif !important;
letter-spacing: 0 !important;
word-spacing: 0 !important;
}
#codepen-footer a {
color: #a7a7a7 !important;
text-decoration: none !important;
}
#codepen-footer a:hover {
color: white !important;
}
</style>
<script>
// Kill alerts, confirmations and prompts
window.alert = function(){};
window.confirm = function(){};
window.prompt = function(){};
window.open = function(){};
window.print = function(){};
</script>
</head>
<body>
<header>
Header information here
</header>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Jobs</a>
<a href="#">Other Things</a>
<a href="#">Many other things</a>
</nav>
<div id="mainContent">
<article>
The main focal point here
</article>
<section>
<div>Content Preview 1</div>
<div>Content Preview 2</div>
<div>Content Preview 3</div>
<div>Content Preview 4</div>
</section>
</div>
<footer>
Footer information here
</footer>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://codepen.io/javascripts/libs/modernizr.js"></script>
<div id="codepen-footer">
<a style="color: #f73535 !important;" href="https://codepen.wufoo.com/forms/m7x3r3/def/field14=" onclick="window.open(this.href, null, 'height=517, width=680, toolbar=0, location=0, status=1, scrollbars=1, resizable=1'); return false">Report Abuse</a>
&nbsp;
<a href="/MikeFielden/pen/holygrailflexbox/9">Edit this Pen</a>
</div>
</body>
</html>
<header>
Header information here
</header>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Jobs</a>
<a href="#">Other Things</a>
<a href="#">Many other things</a>
</nav>
<div id="mainContent">
<article>
The main focal point here
</article>
<section>
<div>Content Preview 1</div>
<div>Content Preview 2</div>
<div>Content Preview 3</div>
<div>Content Preview 4</div>
</section>
</div>
<footer>
Footer information here
</footer>
@import "compass";
@font-face {
font-family: 'Muli';
font-style: normal;
font-weight: 400;
src: local('Muli'), url(http://themes.googleusercontent.com/static/fonts/muli/v4/minRpKQdEvXRRS8oAbAtWvesZW2xOQ-xsNqO47m55DA.woff) format('woff');
}
@mixin display-flex {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
}
@mixin flex-direction ($direction: row) {
-webkit-flex-direction: $direction;
-moz-flex-direction: $direction;
-ms-flex-direction: $direction;
-o-flex-direction: $direction;
flex-direction: $direction;
}
@mixin justify-content ($direction: center) {
-webkit-justify-content: $direction;
-moz-justify-content: $direction;
-ms-justify-content: $direction;
-o-justify-content: $direction;
justify-content: $direction;
}
// Dont currently understand them :) looking into it
@mixin flex($parameters) {
-webkit-flex: $parameters;
-moz-flex: $parameters;
-ms-flex: $parameters;
-o-flex: $parameters;
flex: $parameters;
}
@mixin order($number) {
-webkit-order: $number;
-moz-order: $number;
-ms-order: $number;
-o-order: $number;
order: $number;
}
@mixin align-items($alignment) {
-webkit-align-items: $alignment;
-moz-align-items: $alignment;
-ms-align-items: $alignment;
-o-align-items: $alignment;
align-items: $alignment;
}
html, body {
height: 100%;
box-sizing: border-box;
}
body {
font-family: 'Muli', Arial;
@include display-flex;
@include flex-direction(column);
@include justify-content(center);
margin: 0 2em;
@include transition(all 500ms ease-in-out);
}
#mainContent {
$maxHeight: 500px;
@include display-flex;
@include flex(1);
max-height: $maxHeight;
> * {
border: 1px solid #ccc;
padding: .25em;
@include border-radius(10px);
}
> article {
@include flex(1 0 0px);
@include order(2);
@include align-items(center);
@include justify-content (center);
@include display-flex;
margin: 0 10px;
text-align: center;
}
> section {
@include display-flex;
@include flex-direction(column);
background: #eee;
width: 200px;
@include order(0);
@include flex(none);
// Little Content preview part
> div {
border: 1px solid rgb(204, 204, 204);
padding: 0.25em;
margin: 0.25em;
background: white;
text-align: center;
@include flex(1);
@include justify-content(center);
@include align-items(center);
-webkit-transition: -webkit-flex 1500ms cubic-bezier(.17, .67, 0, 1.45);
&:hover {
@include flex(4);
}
&:first-child {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
&:last-child {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
}
}
}
nav {
@include display-flex;
@include justify-content(space-between);
@include align-items(center);
@include flex(none);
margin-bottom: 10px;
a {
padding: 15px;
background: -webkit-linear-gradient(top, navy 50%, black) no-repeat 50% 100%, navy;
color: white;
display: block;
margin: auto 10px;
@include border-radius(5px);
text-decoration: none;
@include transition(background-size 100ms ease-in-out);
@include transition(font-size 100ms ease-in-out, 500ms);
background-size: 100% 0;
text-align: center;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
@include flex(1);
&:first-child {
margin-left: 0;
}
&:last-child {
margin-right: 0;
}
&:hover {
background-size: 100% 100%;
}
}
}
header,
footer {
$shadowColor: rgba(255, 255, 255, .75);
@include display-flex;
@include justify-content(flex-start);
@include align-items(center);
@include flex(0 0 20px);
background: #eee;
padding: 1em;
margin: 10px 0;
@include border-radius(10px);
color: rgba(0, 0, 0, .6);
@include text-shadow (0 1px $shadowColor);
}
footer {
@include justify-content(flex-end);
}
// Media Queries
@media all and (max-width: 600px) {
body {
margin: 0 10px;
@include justify-content(flex-start);
}
#mainContent {
-webkit-flex-flow: column;
> article {
margin: 0;
}
> section {
margin: 10px auto;
> div {
@include flex(1 0 auto);
}
}
}
#mainContent > article,
#mainContent > section,
nav {
@include order(0);
width: auto;
}
nav {
font-size: 60%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment