_grid.scss 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. // ==========================================================================
  2. // GRID SYSTEM - CSS Grid Layout Utilities (Cross-browser with Mixins)
  3. // ==========================================================================
  4. @use '../abstracts/variables' as v;
  5. @use '../abstracts/mixins' as mix;
  6. @use 'sass:map';
  7. // ==========================================================================
  8. // Display Grid Utilities (using mixins)
  9. // ==========================================================================
  10. .d-grid {
  11. @include mix.grid-display();
  12. gap: map.get(v.$spacers, 3);
  13. }
  14. // Responsive grid display utilities
  15. @each $breakpoint, $value in v.$breakpoints {
  16. @include mix.respond-to-min($breakpoint) {
  17. .d-#{$breakpoint}-grid {
  18. @include mix.grid-display();
  19. gap: map.get(v.$spacers, 3);
  20. }
  21. }
  22. }
  23. // ==========================================================================
  24. // Base Grid Container (using mixins)
  25. // ==========================================================================
  26. .grid {
  27. @include mix.grid(1, v.$grid-gap-base);
  28. // Grid gap variations using spacers
  29. @each $key, $value in v.$spacers {
  30. &.gap-#{$key} { gap: $value; }
  31. &.gap-x-#{$key} { column-gap: $value; }
  32. &.gap-y-#{$key} { row-gap: $value; }
  33. }
  34. }
  35. // ==========================================================================
  36. // Grid Columns - Explicit Grid (cross-browser)
  37. // ==========================================================================
  38. // Fixed column grids (1-12 columns) using mixins
  39. @for $i from 1 through 12 {
  40. .grid-cols-#{$i} {
  41. @include mix.grid($i, v.$grid-gap-base);
  42. }
  43. }
  44. // Auto-fit grids with minimum column sizes (using mixins)
  45. .grid-auto-fit {
  46. @include mix.grid-auto-fit(300px);
  47. // Different minimum sizes
  48. &.min-200 { @include mix.grid-auto-fit(200px); }
  49. &.min-250 { @include mix.grid-auto-fit(250px); }
  50. &.min-300 { @include mix.grid-auto-fit(300px); }
  51. &.min-350 { @include mix.grid-auto-fit(350px); }
  52. &.min-400 { @include mix.grid-auto-fit(400px); }
  53. }
  54. // Auto-fill grids (using mixins)
  55. .grid-auto-fill {
  56. @include mix.grid-auto-fill(300px);
  57. // Different minimum sizes
  58. &.min-200 { @include mix.grid-auto-fill(200px); }
  59. &.min-250 { @include mix.grid-auto-fill(250px); }
  60. &.min-300 { @include mix.grid-auto-fill(300px); }
  61. &.min-350 { @include mix.grid-auto-fill(350px); }
  62. &.min-400 { @include mix.grid-auto-fill(400px); }
  63. }
  64. // ==========================================================================
  65. // Grid Rows (cross-browser)
  66. // ==========================================================================
  67. // Fixed row grids
  68. @for $i from 1 through 6 {
  69. .grid-rows-#{$i} {
  70. -ms-grid-rows: repeat(#{$i}, 1fr);
  71. grid-template-rows: repeat(#{$i}, 1fr);
  72. }
  73. }
  74. // Auto rows
  75. .grid-rows-auto {
  76. -ms-grid-rows: repeat(auto-fit, 1fr);
  77. grid-template-rows: repeat(auto-fit, 1fr);
  78. }
  79. // ==========================================================================
  80. // Grid Item Spanning (cross-browser)
  81. // ==========================================================================
  82. // Column spanning
  83. @for $i from 1 through 12 {
  84. .col-span-#{$i} {
  85. -ms-grid-column-span: #{$i};
  86. grid-column: span #{$i} / span #{$i};
  87. }
  88. }
  89. .col-span-full {
  90. -ms-grid-column: 1;
  91. -ms-grid-column-span: 12;
  92. grid-column: 1 / -1;
  93. }
  94. // Row spanning
  95. @for $i from 1 through 6 {
  96. .row-span-#{$i} {
  97. -ms-grid-row-span: #{$i};
  98. grid-row: span #{$i} / span #{$i};
  99. }
  100. }
  101. .row-span-full {
  102. -ms-grid-row: 1;
  103. -ms-grid-row-span: 6;
  104. grid-row: 1 / -1;
  105. }
  106. // ==========================================================================
  107. // Grid Item Positioning (cross-browser)
  108. // ==========================================================================
  109. // Column start/end
  110. @for $i from 1 through 13 {
  111. .col-start-#{$i} {
  112. -ms-grid-column: #{$i};
  113. grid-column-start: #{$i};
  114. grid-column: #{$i} / span 1;
  115. }
  116. .col-end-#{$i} {
  117. grid-column-end: #{$i};
  118. }
  119. }
  120. // Row start/end
  121. @for $i from 1 through 7 {
  122. .row-start-#{$i} {
  123. -ms-grid-row: #{$i};
  124. grid-row-start: #{$i};
  125. grid-row: #{$i} / span 1;
  126. }
  127. .row-end-#{$i} {
  128. grid-row-end: #{$i};
  129. }
  130. }
  131. // ==========================================================================
  132. // Grid Alignment (using mixins - renamed to avoid conflicts with flex)
  133. // ==========================================================================
  134. // Justify items (horizontal alignment of grid items)
  135. .grid-justify-items-start { @include mix.grid-justify-items(start); }
  136. .grid-justify-items-end { @include mix.grid-justify-items(end); }
  137. .grid-justify-items-center { @include mix.grid-justify-items(center); }
  138. .grid-justify-items-stretch { @include mix.grid-justify-items(stretch); }
  139. // Align items (vertical alignment of grid items) - renamed from align-items-*
  140. .grid-align-items-start { @include mix.grid-align-items(start); }
  141. .grid-align-items-end { @include mix.grid-align-items(end); }
  142. .grid-align-items-center { @include mix.grid-align-items(center); }
  143. .grid-align-items-stretch { @include mix.grid-align-items(stretch); }
  144. // Justify content (horizontal alignment of grid itself)
  145. .grid-justify-content-start { justify-content: start; }
  146. .grid-justify-content-end { justify-content: end; }
  147. .grid-justify-content-center { justify-content: center; }
  148. .grid-justify-content-stretch { justify-content: stretch; }
  149. .grid-justify-content-around { justify-content: space-around; }
  150. .grid-justify-content-between { justify-content: space-between; }
  151. .grid-justify-content-evenly { justify-content: space-evenly; }
  152. // Align content (vertical alignment of grid itself)
  153. .grid-align-content-start { align-content: start; }
  154. .grid-align-content-end { align-content: end; }
  155. .grid-align-content-center { align-content: center; }
  156. .grid-align-content-stretch { align-content: stretch; }
  157. .grid-align-content-around { align-content: space-around; }
  158. .grid-align-content-between { align-content: space-between; }
  159. .grid-align-content-evenly { align-content: space-evenly; }
  160. // Place items (shorthand for justify-items + align-items) - using mixins
  161. .grid-place-items-start { @include mix.place-items(start); }
  162. .grid-place-items-end { @include mix.place-items(end); }
  163. .grid-place-items-center { @include mix.place-items(center); }
  164. .grid-place-items-stretch { @include mix.place-items(stretch); }
  165. // ==========================================================================
  166. // Responsive Grid Classes (using mixins and cross-browser)
  167. // ==========================================================================
  168. // Small screens and up
  169. @media (min-width: map.get(v.$breakpoints, 'sm')) {
  170. @for $i from 1 through 12 {
  171. .sm\:grid-cols-#{$i} {
  172. @include mix.grid($i, v.$grid-gap-base);
  173. }
  174. }
  175. .sm\:grid-auto-fit {
  176. @include mix.grid-auto-fit(300px);
  177. &.min-200 { @include mix.grid-auto-fit(200px); }
  178. &.min-250 { @include mix.grid-auto-fit(250px); }
  179. &.min-300 { @include mix.grid-auto-fit(300px); }
  180. &.min-350 { @include mix.grid-auto-fit(350px); }
  181. }
  182. @for $i from 1 through 12 {
  183. .sm\:col-span-#{$i} {
  184. -ms-grid-column-span: #{$i};
  185. grid-column: span #{$i} / span #{$i};
  186. }
  187. }
  188. }
  189. // Medium screens and up
  190. @media (min-width: map.get(v.$breakpoints, 'md')) {
  191. @for $i from 1 through 12 {
  192. .md\:grid-cols-#{$i} {
  193. @include mix.grid($i, v.$grid-gap-base);
  194. }
  195. }
  196. .md\:grid-auto-fit {
  197. @include mix.grid-auto-fit(300px);
  198. &.min-200 { @include mix.grid-auto-fit(200px); }
  199. &.min-250 { @include mix.grid-auto-fit(250px); }
  200. &.min-300 { @include mix.grid-auto-fit(300px); }
  201. &.min-350 { @include mix.grid-auto-fit(350px); }
  202. }
  203. @for $i from 1 through 12 {
  204. .md\:col-span-#{$i} {
  205. -ms-grid-column-span: #{$i};
  206. grid-column: span #{$i} / span #{$i};
  207. }
  208. }
  209. }
  210. // Large screens and up
  211. @media (min-width: map.get(v.$breakpoints, 'lg')) {
  212. @for $i from 1 through 12 {
  213. .lg\:grid-cols-#{$i} {
  214. @include mix.grid($i, v.$grid-gap-base);
  215. }
  216. }
  217. .lg\:grid-auto-fit {
  218. @include mix.grid-auto-fit(300px);
  219. &.min-200 { @include mix.grid-auto-fit(200px); }
  220. &.min-250 { @include mix.grid-auto-fit(250px); }
  221. &.min-300 { @include mix.grid-auto-fit(300px); }
  222. &.min-350 { @include mix.grid-auto-fit(350px); }
  223. }
  224. @for $i from 1 through 12 {
  225. .lg\:col-span-#{$i} {
  226. -ms-grid-column-span: #{$i};
  227. grid-column: span #{$i} / span #{$i};
  228. }
  229. }
  230. }
  231. // Extra large screens and up
  232. @media (min-width: map.get(v.$breakpoints, 'xl')) {
  233. @for $i from 1 through 12 {
  234. .xl\:grid-cols-#{$i} {
  235. @include mix.grid($i, v.$grid-gap-base);
  236. }
  237. }
  238. .xl\:grid-auto-fit {
  239. @include mix.grid-auto-fit(300px);
  240. &.min-200 { @include mix.grid-auto-fit(200px); }
  241. &.min-250 { @include mix.grid-auto-fit(250px); }
  242. &.min-300 { @include mix.grid-auto-fit(300px); }
  243. &.min-350 { @include mix.grid-auto-fit(350px); }
  244. }
  245. @for $i from 1 through 12 {
  246. .xl\:col-span-#{$i} {
  247. -ms-grid-column-span: #{$i};
  248. grid-column: span #{$i} / span #{$i};
  249. }
  250. }
  251. }
  252. // ==========================================================================
  253. // Grid Utilities (cross-browser)
  254. // ==========================================================================
  255. // Auto-sizing grid items
  256. .grid-item-auto {
  257. -ms-grid-column: auto;
  258. -ms-grid-row: auto;
  259. grid-column: auto;
  260. grid-row: auto;
  261. }
  262. // Aspect ratio helpers for grid items
  263. .grid-item-square {
  264. aspect-ratio: 1 / 1;
  265. }
  266. .grid-item-landscape {
  267. aspect-ratio: 16 / 9;
  268. }
  269. .grid-item-portrait {
  270. aspect-ratio: 3 / 4;
  271. }
  272. // Grid debugging
  273. .grid-debug {
  274. .grid {
  275. border: 2px dashed red;
  276. background: rgba(255, 0, 0, 0.05);
  277. }
  278. [class*="col-span"],
  279. [class*="row-span"],
  280. .grid > * {
  281. border: 1px dashed blue;
  282. background: rgba(0, 0, 255, 0.05);
  283. position: relative;
  284. &::after {
  285. content: attr(class);
  286. position: absolute;
  287. top: 0;
  288. left: 0;
  289. background: rgba(0, 0, 0, 0.8);
  290. color: white;
  291. font-size: 10px;
  292. padding: 2px 4px;
  293. z-index: 1000;
  294. }
  295. }
  296. }