_grid.scss 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Grid system
  2. //
  3. // Generate semantic grid columns with these mixins.
  4. @mixin make-row($gutter: $grid-gutter-width) {
  5. --#{$variable-prefix}gutter-x: #{$gutter};
  6. --#{$variable-prefix}gutter-y: 0;
  7. display: flex;
  8. flex-wrap: wrap;
  9. margin-top: calc(var(--#{$variable-prefix}gutter-y) * -1); // stylelint-disable-line function-disallowed-list
  10. margin-right: calc(var(--#{$variable-prefix}gutter-x) * -.5); // stylelint-disable-line function-disallowed-list
  11. margin-left: calc(var(--#{$variable-prefix}gutter-x) * -.5); // stylelint-disable-line function-disallowed-list
  12. }
  13. @mixin make-col-ready($gutter: $grid-gutter-width) {
  14. // Add box sizing if only the grid is loaded
  15. box-sizing: if(variable-exists(include-column-box-sizing) and $include-column-box-sizing, border-box, null);
  16. // Prevent columns from becoming too narrow when at smaller grid tiers by
  17. // always setting `width: 100%;`. This works because we set the width
  18. // later on to override this initial width.
  19. flex-shrink: 0;
  20. width: 100%;
  21. max-width: 100%; // Prevent `.col-auto`, `.col` (& responsive variants) from breaking out the grid
  22. padding-right: calc(var(--#{$variable-prefix}gutter-x) * .5); // stylelint-disable-line function-disallowed-list
  23. padding-left: calc(var(--#{$variable-prefix}gutter-x) * .5); // stylelint-disable-line function-disallowed-list
  24. margin-top: var(--#{$variable-prefix}gutter-y);
  25. }
  26. @mixin make-col($size: false, $columns: $grid-columns) {
  27. @if $size {
  28. flex: 0 0 auto;
  29. width: percentage(divide($size, $columns));
  30. } @else {
  31. flex: 1 1 0;
  32. max-width: 100%;
  33. }
  34. }
  35. @mixin make-col-auto() {
  36. flex: 0 0 auto;
  37. width: auto;
  38. }
  39. @mixin make-col-offset($size, $columns: $grid-columns) {
  40. $num: divide($size, $columns);
  41. margin-left: if($num == 0, 0, percentage($num));
  42. }
  43. // Row columns
  44. //
  45. // Specify on a parent element(e.g., .row) to force immediate children into NN
  46. // numberof columns. Supports wrapping to new lines, but does not do a Masonry
  47. // style grid.
  48. @mixin row-cols($count) {
  49. > * {
  50. flex: 0 0 auto;
  51. width: divide(100%, $count);
  52. }
  53. }
  54. // Framework grid generation
  55. //
  56. // Used only by Bootstrap to generate the correct number of grid classes given
  57. // any value of `$grid-columns`.
  58. @mixin make-grid-columns($columns: $grid-columns, $gutter: $grid-gutter-width, $breakpoints: $grid-breakpoints) {
  59. @each $breakpoint in map-keys($breakpoints) {
  60. // .row-cols defaults must all appear before .col overrides so they can be overridden.
  61. $infix: breakpoint-infix($breakpoint, $breakpoints);
  62. @include media-breakpoint-up($breakpoint, $breakpoints) {
  63. // Provide basic `.col-{bp}` classes for equal-width flexbox columns
  64. .col#{$infix} {
  65. flex: 1 0 0%; // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4
  66. }
  67. .row-cols#{$infix}-auto > * {
  68. @include make-col-auto();
  69. }
  70. @if $grid-row-columns > 0 {
  71. @for $i from 1 through $grid-row-columns {
  72. .row-cols#{$infix}-#{$i} {
  73. @include row-cols($i);
  74. }
  75. }
  76. }
  77. }
  78. }
  79. @each $breakpoint in map-keys($breakpoints) {
  80. $infix: breakpoint-infix($breakpoint, $breakpoints);
  81. @include media-breakpoint-up($breakpoint, $breakpoints) {
  82. .col#{$infix}-auto {
  83. @include make-col-auto();
  84. }
  85. @if $columns > 0 {
  86. @for $i from 1 through $columns {
  87. .col#{$infix}-#{$i} {
  88. @include make-col($i, $columns);
  89. }
  90. }
  91. // `$columns - 1` because offsetting by the width of an entire row isn't possible
  92. @for $i from 0 through ($columns - 1) {
  93. @if not ($infix == "" and $i == 0) { // Avoid emitting useless .offset-0
  94. .offset#{$infix}-#{$i} {
  95. @include make-col-offset($i, $columns);
  96. }
  97. }
  98. }
  99. }
  100. // Gutters
  101. //
  102. // Make use of `.g-*`, `.gx-*` or `.gy-*` utilities to change spacing between the columns.
  103. @each $key, $value in $gutters {
  104. .g#{$infix}-#{$key},
  105. .gx#{$infix}-#{$key} {
  106. --#{$variable-prefix}gutter-x: #{$value};
  107. }
  108. .g#{$infix}-#{$key},
  109. .gy#{$infix}-#{$key} {
  110. --#{$variable-prefix}gutter-y: #{$value};
  111. }
  112. }
  113. }
  114. }
  115. }