Skip to content

Instantly share code, notes, and snippets.

@angellromero
Created October 5, 2016 20:20
Show Gist options
  • Save angellromero/7004240a6e089d2c20a87e1ee54d7728 to your computer and use it in GitHub Desktop.
Save angellromero/7004240a6e089d2c20a87e1ee54d7728 to your computer and use it in GitHub Desktop.
Flex Grid Mixin
// 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