grid + scss 20行代码实现 bootstrap 栅格系统

vscode插件

html文件的热加载
image.png
sass编译
image.png

栅格核心

style.scss

  1. .row {
  2. display: grid;
  3. grid-template-columns: repeat(12, 1fr);
  4. gap: 10px;
  5. }
  6. @media screen and (max-width:768px) {
  7. @import "./sm.scss";
  8. }
  9. @media screen and (min-width:768px) and (max-width:1000px) {
  10. @import "./md.scss";
  11. }
  12. @media screen and (min-width:1000px) {
  13. @import "./lg.scss";
  14. }

sm.scss

  1. @for $i from 1 through 12 {
  2. .col-md-#{$i} {
  3. grid-column: span #{$i};
  4. }
  5. }

md.scss

  1. @for $i from 1 through 12 {
  2. .col-md-#{$i} {
  3. grid-column: span #{$i};
  4. }
  5. }

lg.scss

  1. @for $i from 1 through 12 {
  2. .col-md-#{$i} {
  3. grid-column: span #{$i};
  4. }
  5. }

完整程序

https://github.com/withwz/grid-with-grid..