_html-grid.scss 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // html-grid.scss v1.0 | @ajlkn | MIT licensed */
  2. // Mixins.
  3. /// Initializes the current element as an HTML grid.
  4. /// @param {mixed} $gutters Gutters (either a single number to set both column/row gutters, or a list to set them individually).
  5. /// @param {mixed} $suffix Column class suffix (optional; either a single suffix or a list).
  6. @mixin html-grid($gutters: 1.5em, $suffix: '') {
  7. // Initialize.
  8. $cols: 12;
  9. $multipliers: 0, 0.25, 0.5, 1, 1.50, 2.00;
  10. $unit: 100% / $cols;
  11. // Suffixes.
  12. $suffixes: null;
  13. @if (type-of($suffix) == 'list') {
  14. $suffixes: $suffix;
  15. }
  16. @else {
  17. $suffixes: ($suffix);
  18. }
  19. // Gutters.
  20. $guttersCols: null;
  21. $guttersRows: null;
  22. @if (type-of($gutters) == 'list') {
  23. $guttersCols: nth($gutters, 1);
  24. $guttersRows: nth($gutters, 2);
  25. }
  26. @else {
  27. $guttersCols: $gutters;
  28. $guttersRows: 0;
  29. }
  30. // Row.
  31. display: flex;
  32. flex-wrap: wrap;
  33. box-sizing: border-box;
  34. align-items: stretch;
  35. // Columns.
  36. > * {
  37. box-sizing: border-box;
  38. }
  39. // Gutters.
  40. &.gtr-uniform {
  41. > * {
  42. > :last-child {
  43. margin-bottom: 0;
  44. }
  45. }
  46. }
  47. // Alignment.
  48. &.aln-left {
  49. justify-content: flex-start;
  50. }
  51. &.aln-center {
  52. justify-content: center;
  53. }
  54. &.aln-right {
  55. justify-content: flex-end;
  56. }
  57. &.aln-top {
  58. align-items: flex-start;
  59. }
  60. &.aln-middle {
  61. align-items: center;
  62. }
  63. &.aln-bottom {
  64. align-items: flex-end;
  65. }
  66. // Step through suffixes.
  67. @each $suffix in $suffixes {
  68. // Suffix.
  69. @if ($suffix != '') {
  70. $suffix: '-' + $suffix;
  71. }
  72. @else {
  73. $suffix: '';
  74. }
  75. // Row.
  76. // Important.
  77. > .imp#{$suffix} {
  78. order: -1;
  79. }
  80. // Columns, offsets.
  81. @for $i from 1 through $cols {
  82. > .col-#{$i}#{$suffix} {
  83. width: $unit * $i;
  84. }
  85. > .off-#{$i}#{$suffix} {
  86. margin-left: $unit * $i;
  87. }
  88. }
  89. // Step through multipliers.
  90. @each $multiplier in $multipliers {
  91. // Gutters.
  92. $class: null;
  93. @if ($multiplier != 1) {
  94. $class: '.gtr-' + ($multiplier * 100);
  95. }
  96. &#{$class} {
  97. margin-top: ($guttersRows * $multiplier * -1);
  98. margin-left: ($guttersCols * $multiplier * -1);
  99. > * {
  100. padding: ($guttersRows * $multiplier) 0 0 ($guttersCols * $multiplier);
  101. }
  102. // Uniform.
  103. &.gtr-uniform {
  104. margin-top: $guttersCols * $multiplier * -1;
  105. > * {
  106. padding-top: $guttersCols * $multiplier;
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }