Last active
October 1, 2017 01:24
-
-
Save AllThingsSmitty/e4b61ac4a3c39ffcfea8 to your computer and use it in GitHub Desktop.
Columns with equal height using Flexbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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­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­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