- 定义动态样式,方便复用
- 样式重置
- 全局 *
- 根元素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; } }
//使用
- flex布局样式定义```css$flex-jc: (start: flex-start,end: flex-end,center: center,between: space-between,around: space-around,);$flex-ai: (start: flex-start,end: flex-end,center: center,stretch: stretch,);// flex.d-flex {display: flex;}.flex-column {flex-direction: column;}.flex-wrap {flex-wrap: wrap;}@each $key, $value in $flex-jc {.jc-#{$key} {justify-content: $value;}}@each $key, $value in $flex-ai {.ai-#{$key} {align-items: $value;}}.flex-1 {flex: 1;}.flex-grow-1 {flex-grow: 1;}//使用举例.d-flex == display:flex.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} {
#{$type}: $size * $spacing-base-size;}
}
// .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} {
#{$type}-left: $size * $spacing-base-size;#{$type}-right: $size * $spacing-base-size;}.#{$typeKey}y-#{$sizeKey} {#{$type}-top: $size * $spacing-base-size;#{$type}-bottom: $size * $spacing-base-size;}
}
// .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} {
#{$type}-#{$direction}: $size * $spacing-base-size;}}
} } ```
