Advertisement
alex91ckua

SCSS flex grid

Mar 15th, 2020
2,500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SAS 1.54 KB | None | 0 0
  1. $grid__bp-sm: 576;
  2. $grid__bp-md: 768;
  3. $grid__bp-lg: 992;
  4. $grid__bp-xl: 1200;
  5. $grid__cols: 12;
  6.  
  7. $map-grid-props: (
  8.         '': 0,
  9.         '-sm': $grid__bp-sm,
  10.         '-md': $grid__bp-md,
  11.         '-lg': $grid__bp-lg,
  12.         '-xl': $grid__bp-xl
  13. );
  14.  
  15. @mixin create-mq($breakpoint, $min-or-max) {
  16.   @if($breakpoint == 0) {
  17.     @content;
  18.   } @else {
  19.     @media screen and (#{$min-or-max}-width: $breakpoint *1px) {
  20.       @content;
  21.     }
  22.   }
  23. }
  24.  
  25. @mixin create-col-classes($modifier, $grid-cols, $breakpoint) {
  26.   @include create-mq($breakpoint, 'min') {
  27.     &col#{$modifier}-offset-0 {
  28.       margin-left: 0;
  29.     }
  30.     @for $i from 1 through $grid-cols {
  31.       &col#{$modifier}-#{$i} {
  32.         flex-basis: (100 / ($grid-cols / $i) ) * 1%;
  33.       }
  34.       &col#{$modifier}-offset-#{$i} {
  35.         margin-left: (100 / ($grid-cols / $i) ) * 1%;
  36.       }
  37.     }
  38.   }
  39. }
  40.  
  41. @each $modifier , $breakpoint in $map-grid-props {
  42.   @if($modifier == '') {
  43.     $modifier: '-xs';
  44.   }
  45.   @include create-mq($breakpoint - 1, 'max') {
  46.     .hidden#{$modifier}-down {
  47.       display: none !important;
  48.     }
  49.   }
  50.   @include create-mq($breakpoint, 'min') {
  51.     .hidden#{$modifier}-up {
  52.       display: none !important;
  53.     }
  54.   }
  55. }
  56.  
  57. @each $modifier , $breakpoint in $map-grid-props {
  58.     @include create-col-classes($modifier, $grid__cols, $breakpoint);
  59. }
  60.  
  61. .container {
  62.   max-width: $grid__bp-xl * 1px;
  63.   margin: 0 auto;
  64.   &--fluid {
  65.     margin: 0;
  66.     max-width: 100%;
  67.   }
  68.   &__row {
  69.     display: flex;
  70.     flex-wrap: wrap;
  71.     width: 100%;
  72.   }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement