Skip to content

Instantly share code, notes, and snippets.

@AllThingsSmitty
Last active October 1, 2017 01:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllThingsSmitty/e4b61ac4a3c39ffcfea8 to your computer and use it in GitHub Desktop.
Save AllThingsSmitty/e4b61ac4a3c39ffcfea8 to your computer and use it in GitHub Desktop.
Columns with equal height using Flexbox
@import url(http://fonts.googleapis.com/css?family=Open+Sans);
html {
background: #444;
box-sizing: border-box;
font-family: "Open Sans", sans-serif;
line-height: 1.4;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
margin: 0;
}
/* before */
/* columns height based on content */
.columns {
font-size: 0;
list-style: none;
margin-left: auto;
margin-right: auto;
max-width: 1280px;
max-width: 80rem;
overflow: hidden;
padding: 8px;
padding: 0.5rem;
}
.column {
display: inline-block;
font-size: 16px;
font-size: 1rem;
padding: 8px;
padding: 0.5rem;
vertical-align: top;
width: 50%;
}
@media (min-width: 30em) {
.column {
width: 33.33333333%;
};
}
@media (min-width: 48em) {
.column {
width: 16.66666666%;
};
}
.tile {
background: #fff;
border: 3px solid #222;
color: #444;
padding: 16px;
padding: 1rem;
}
.tile-main,
.tile-footer {
margin: 0;
}
.tile-main {
font-size: 18px;
font-size: 1.125rem;
margin-bottom: 4px;
margin-bottom: 0.25rem;
}
.tile-footer {
color: #aaa;
}
/* after */
/* Flexbox to the rescue */
.columns, .column, .tile {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.columns {
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.column, .tile {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.tile, .tile-main {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
}
<ul class="columns">
<li class="column">
<div class="tile">
<p class="tile-main">The Man in the High Castle</p>
<p class="tile-footer"><time>1962</time></p>
</div>
</li>
<li class="column">
<div class="tile">
<p class="tile-main">Martian Time-Slip</p>
<p class="tile-footer"><time>1964</time></p>
</div>
</li>
<li class="column">
<div class="tile">
<p class="tile-main">Do An&shy;droids Dream of Electric Sheep?</p>
<p class="tile-footer"><time>1968</time></p>
</div>
</li>
<li class="column">
<div class="tile">
<p class="tile-main">Ubik</p>
<p class="tile-footer"><time>1969</time></p>
</div>
</li>
<li class="column">
<div class="tile">
<p class="tile-main">Flow My Tears, the Police&shy;man Said</p>
<p class="tile-footer"><time>1974</time></p>
</div>
</li>
<li class="column">
<div class="tile">
<p class="tile-main">A Scanner Darkly</p>
<p class="tile-footer"><time>1977</time></p>
</div>
</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment