Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. /// ----------------------
  2. /// CSS GRID - IE POLYFILL
  3. /// ----------------------
  4. ///
  5. /// Write CSS grid-like code and get native CSS Grid in modern browsers and MS Grid in IE 10+
  6. ///
  7. /// Documentation
  8. /// -------------
  9. /// Just @include ieGrid($col) and pass the number of columns.
  10. /// If you want more than one row, set the max number of rows in the second param (1 by default)
  11. ///
  12. /// To add gaps, use @include ieGridGaps($width, $height), ommit height if width and height are equal
  13.  
  14. @mixin ieGrid($cols, $rows: 1) {
  15. @supports(display: grid) {
  16. display: grid !important;
  17. }
  18.  
  19. display: -ms-grid;
  20.  
  21. @if (type-of($cols) == number) {
  22. @include ieGridColumns($cols);
  23.  
  24. & > * {
  25. @include ieGridElements($cols, $rows);
  26. }
  27. } @else {
  28. grid-template-columns: unquote($cols);
  29. -ms-grid-columns: unquote($cols);
  30. }
  31.  
  32. @if ($rows > 1) {
  33. @include ieGridRows($rows);
  34. }
  35. }
  36.  
  37. @mixin ieGridColumns($cols) {
  38. $colStr: "";
  39.  
  40. @for $i from 1 through $cols {
  41. $colStr: $colStr + "1fr ";
  42. }
  43.  
  44. grid-template-columns: repeat($cols, 1fr);
  45. -ms-grid-columns: unquote($colStr);
  46. }
  47.  
  48. @mixin ieGridRows($rows) {
  49. $rowStr: "";
  50.  
  51. @for $i from 1 through $rows {
  52. $rowStr: $rowStr + "1fr ";
  53. }
  54.  
  55. -ms-grid-rows: unquote($rowStr);
  56. }
  57.  
  58. @mixin ieGridElements($cols, $rows: 1) {
  59. @for $i from 1 through $cols {
  60. &:nth-child(#{$cols}n + #{$i}) {
  61. -ms-grid-column: $i;
  62. }
  63. }
  64.  
  65. @for $j from 0 through $rows {
  66. &:nth-child(n + #{$cols * $j + 1}):nth-child(-n + #{$cols * ($j + 1)}) {
  67. -ms-grid-row: $j + 1;
  68. }
  69. }
  70. }
  71.  
  72. @mixin ieGridGap($colGap, $rowGap: 0) {
  73. @if ($rowGap > 0) {
  74. grid-column-gap: $colGap;
  75. grid-row-gap: $rowGap;
  76.  
  77. & > * {
  78. margin: $rowGap / 2 $colGap / 2;
  79.  
  80. @supports(grid-column-gap: $colGap) {
  81. margin: 0;
  82. }
  83. }
  84. } @else {
  85. grid-gap: $colGap;
  86.  
  87. & > * {
  88. margin: $colGap / 2;
  89.  
  90. @supports(grid-gap: $colGap) {
  91. margin: 0;
  92. }
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement