• 定义动态样式,方便复用
    • 样式重置
      • 全局 *
      • 根元素html、body、a
    • 样式定义 (变量+循环)
      • 小程序的色彩和字体定义 ```css

    //定义常用色彩对象 $colors: ( ‘primary’: #db9e3f, ‘info’: #4b67af, ‘danger’: #791a15, ‘blue’: #4394e4, ‘white’: #fff, ‘black’: #000, );

    //循环色彩对象定义字体、背景色彩 @each $colorKey, $color in $colors { .text-#{$colorKey} { color: $color; } .bg-#{$colorKey} { background-color: $color; } }

    //字体 align @each $var in (left, center, right) { .text-#{$var} { text-align: $var !important; } }

    //使用

    字体

    背景

    1. - flex布局样式定义
    2. ```css
    3. $flex-jc: (
    4. start: flex-start,
    5. end: flex-end,
    6. center: center,
    7. between: space-between,
    8. around: space-around,
    9. );
    10. $flex-ai: (
    11. start: flex-start,
    12. end: flex-end,
    13. center: center,
    14. stretch: stretch,
    15. );
    16. // flex
    17. .d-flex {
    18. display: flex;
    19. }
    20. .flex-column {
    21. flex-direction: column;
    22. }
    23. .flex-wrap {
    24. flex-wrap: wrap;
    25. }
    26. @each $key, $value in $flex-jc {
    27. .jc-#{$key} {
    28. justify-content: $value;
    29. }
    30. }
    31. @each $key, $value in $flex-ai {
    32. .ai-#{$key} {
    33. align-items: $value;
    34. }
    35. }
    36. .flex-1 {
    37. flex: 1;
    38. }
    39. .flex-grow-1 {
    40. flex-grow: 1;
    41. }
    42. //使用举例
    43. .d-flex == display:flex
    44. .jc-between == justify-content: space-between;
    • 常用边距定义 ```css // spacing // 0-5: 0 // .mt-1 => margin top .pb-2

    $spacing-types: ( m: margin, p: padding, );

    $spacing-directions: ( t: top, r: right, b: bottom, l: left, );

    $spacing-base-size: 1rem;

    $spacing-sizes: ( 0: 0, 1: 0.25, 2: 0.5, 3: 1, 4: 1.5, 5: 3, );

    // .m-1 == margin: 0.25rem @each $typeKey, $type in $spacing-types { @each $sizeKey, $size in $spacing-sizes { .#{$typeKey}-#{$sizeKey} {

    1. #{$type}: $size * $spacing-base-size;
    2. }

    }

    // .mx-1 , .my-1 // .mx-3 == margin-left: 1rem; margin-right: 1rem; // .py-3 == padding-top: 1rem; padding-bottom: 1rem; @each $sizeKey, $size in $spacing-sizes { .#{$typeKey}x-#{$sizeKey} {

    1. #{$type}-left: $size * $spacing-base-size;
    2. #{$type}-right: $size * $spacing-base-size;
    3. }
    4. .#{$typeKey}y-#{$sizeKey} {
    5. #{$type}-top: $size * $spacing-base-size;
    6. #{$type}-bottom: $size * $spacing-base-size;
    7. }

    }

    // .mt-1 // .mt-3 == margin-top: 1rem // .pb-3 == padding-bottom: 1rem; @each $directionKey, $direction in $spacing-directions { @each $sizeKey, $size in $spacing-sizes { .#{$typeKey}#{$directionKey}-#{$sizeKey} {

    1. #{$type}-#{$direction}: $size * $spacing-base-size;
    2. }
    3. }

    } } ```