Created
October 5, 2016 20:20
-
-
Save angellromero/7004240a6e089d2c20a87e1ee54d7728 to your computer and use it in GitHub Desktop.
Flex Grid Mixin
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
// Uses Flexbox to create grid with container's direct descendant elements | |
.flex-grid(@columns: 2, @margin: @indent-md) { | |
@total-margin: (@columns - 1) * @margin; | |
@first-column-offset: @columns + 1; | |
.flex(); | |
.flex-wrap(wrap); | |
> * { | |
box-sizing: border-box; | |
.flex-justify-content(space-between); | |
width: ~'calc( ( 100% -'@total-margin~')/'@columns~')'; | |
&:not(:nth-child(@{columns}n + 1)) { | |
margin-left: @margin; | |
} | |
&:nth-child(n + @{first-column-offset}) { | |
margin-top: @margin; | |
} | |
} | |
@media screen and (max-width: @screen-md) { | |
> * { | |
width: 100%; | |
&:not(:last-child) { | |
margin-bottom: @margin; | |
} | |
&:not(:nth-child(@{columns}n + 1)), | |
&:nth-child(n + @{first-column-offset}) { | |
margin-top: 0; | |
margin-left: 0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment