Last active
July 29, 2017 14:30
-
-
Save stevenkaspar/9715ae1faad1ba82b5e2eb2980a41fdb to your computer and use it in GitHub Desktop.
Sass Responsive Cards
This file contains 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
/** | |
* - num columns per card | |
* - num possible column | |
* - include @cards > * > * as a flex item | |
*/ | |
@mixin cards($card-columns: 4, $possible-columns: 12, $flex: true){ | |
width: 100%; | |
display: -webkit-flex; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-flex-wrap: wrap; | |
-ms-flex-wrap: wrap; | |
flex-wrap: wrap; | |
> * { | |
float: left; | |
width: percentage($card-columns / $possible-columns); | |
@if $flex == true { | |
> * { | |
-webkit-box-flex: 1; | |
-webkit-flex: 1 0 0%; | |
-ms-flex: 1 0 0%; | |
flex: 1 0 0%; | |
position: relative; | |
display: -webkit-box; | |
display: -webkit-flex; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-orient: vertical; | |
-webkit-box-direction: normal; | |
-webkit-flex-direction: column; | |
-ms-flex-direction: column; | |
flex-direction: column; | |
} | |
} | |
} | |
} |
This file contains 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
.card-list { | |
@media (min-width: 768px){ | |
@include cards(3); | |
} | |
@media (min-width: 400px) and (max-width: 768px){ | |
@include cards(4); | |
} | |
.card-list-container { | |
height: 100%; | |
position: relative; | |
.card-list-body { | |
-webkit-box-flex: 1; | |
-webkit-flex: 1 1 auto; | |
-ms-flex: 1 1 auto; | |
flex: 1 1 auto; | |
padding: 1.25rem; | |
} | |
} | |
} |
This file contains 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='card-list'> | |
<!-- foreach --> | |
<li> | |
<div class='card-list-container'> | |
<img alt="alt" src="..."/> | |
<div class='card-list-body'> | |
<p> | |
body content | |
</p> | |
</div> | |
<div> | |
footer content | |
</div> | |
</div> | |
</li> | |
<!-- endforeach --> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment