Skip to content

Instantly share code, notes, and snippets.

@davemac
Last active October 5, 2017 04:00
Show Gist options
  • Save davemac/ebff99a6723d9f313621d6465c0f55bb to your computer and use it in GitHub Desktop.
Save davemac/ebff99a6723d9f313621d6465c0f55bb to your computer and use it in GitHub Desktop.
Responsive content grid with flexbox and scss
.flex-row{
display: flex;
// shorthand for flex-direction & flex-wrap
flex-flow: row wrap;
justify-content: space-between;
align-items: flex-start;
@media #{$small-only} {
display: block;
}
.flex-item{
margin-bottom: 12px;
}
}
.dmc-half{
.flex-item{
// shorthand for flex-grow, flex-shrink & flex-basis
flex: 0 1 calc(50% - 6px);
}
}
.dmc-third{
.flex-item{
flex: 0 1 calc(33% - 6px);
}
}
@davemac
Copy link
Author

davemac commented Oct 5, 2017

This is for a 2 or 3 column content layout grid (eg image gallery) but to change the number of columns simply change flex-basis, either with a class or a media query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment