Skip to content

Instantly share code, notes, and snippets.

@treetrum
Last active February 9, 2018 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treetrum/ce9c7771fcb29906cd5e1c7e62e47fd9 to your computer and use it in GitHub Desktop.
Save treetrum/ce9c7771fcb29906cd5e1c7e62e47fd9 to your computer and use it in GitHub Desktop.
Sass Mixin to create a flex grid with inside/internal borders Raw
@mixin flexGridWithInsideBorders( $numberOfColumns, $borderColor: hsl(0, 0, 90%), $borderWidth: 1px, $borderStyle: solid, $numberOfItemsInLastRow: false) {
// Handle default numberOfItemsInLastRow
@if ( $numberOfItemsInLastRow == false ) { $numberOfItemsInLastRow: $numberOfColumns; }
// Setup the base flex grid
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
& > * {
// Setup the item widths
width: (100%) / $numberOfColumns;
// Setup the item borders
border-right: $borderWidth $borderStyle $borderColor;
border-bottom: $borderWidth $borderStyle $borderColor;
// Remove the border right from the last item in each row
&:nth-child(#{$numberOfColumns}n+#{$numberOfColumns}) {
border-right: 0;
}
// Remove the border botom from each item in the last row
@for $i from 1 through $numberOfItemsInLastRow {
&:nth-last-child(#{$i}) {
border-bottom: 0;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment