Created
January 14, 2014 21:34
-
-
Save awkale/8426221 to your computer and use it in GitHub Desktop.
Masonry - calc() sizing - fixed gutter, % column
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
<h1>Masonry - calc() sizing</h1> | |
<div class="masonry js-masonry" data-masonry-options='{ "columnWidth": ".grid-sizer", "itemSelector": ".item", "gutter": 20 }'> | |
<div class="grid-sizer"></div> | |
<div class="item"></div> | |
<div class="item w2 h2"></div> | |
<div class="item h3"></div> | |
<div class="item h2"></div> | |
<div class="item w3"></div> | |
<div class="item"></div> | |
<div class="item"></div> | |
<div class="item h2"></div> | |
<div class="item w2 h3"></div> | |
<div class="item"></div> | |
<div class="item h2"></div> | |
<div class="item"></div> | |
<div class="item w2 h2"></div> | |
<div class="item w2"></div> | |
<div class="item"></div> | |
<div class="item h2"></div> | |
<div class="item"></div> | |
<div class="item"></div> | |
<div class="item h3"></div> | |
<div class="item h2"></div> | |
<div class="item"></div> | |
<div class="item"></div> | |
<div class="item h2"></div> | |
</div> |
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
// http://masonry.desandro.com/masonry.pkgd.js added as external resource |
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
* { | |
box-sizing: border-box; | |
} | |
body { font-family: sans-serif; } | |
.masonry { | |
background: #EEE; | |
max-width: 640px; | |
} | |
.masonry .item, | |
.masonry .grid-sizer { | |
width: calc( ( 100% - 60px ) / 4 ); | |
height: 60px; | |
float: left; | |
background: #D26; | |
border: 2px solid #333; | |
border-color: hsla(0, 0%, 0%, 0.5); | |
border-radius: 5px; | |
margin-bottom: 20px; | |
} | |
.item.w2 { width: calc( ( 100% - 60px ) * ( 2 / 4 ) + 20px ); } | |
.item.w3 { width: 100%; } | |
.item.h2 { height: 100px; } | |
.item.h3 { height: 130px; } | |
.item.h4 { height: 180px; } |
if I work out a good IE8 polyfill and/or fallback I'll add it here later, seriously great gist mate nice one.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks man, this is excellent!