确保项目能使用scss
然后创建一个名为 total.scss 的scss样式文件
将以下代码放入
1 $spacing-types: ( //类型
2 m: margin,
3 p: padding
4 );
5 $spacing-directions: ( //位置
6 t: top,
7 b: bottom,
8 l: left,
9 r: right
10 );
11
12 $spacing-base-size : 10px; //基数
13 $spacing-sizes: ( //需要的边距可以添加
14 0: 0,
15 1: 1,
16 2: 2,
17 3: 3,
18 4: 4,
19 5: 5
20 );
21
22 // 循环出 margin 与 padding 的各类值
23
24 @each $typeKey, $type in $spacing-types {
25 // m-1{margin:10px} || p-5{padding:50px}
26 @each $sizeKey, $size in $spacing-sizes {
27 .#{$typeKey}-#{$sizeKey} {
28 #{$type}: $size * $spacing-base-size;
29 }
30 }
31 // mx-1{marfin-left:10px;marfin-right:10px} || px-5{padding-left:50px;padding-right:50px;}
32 @each $sizeKey, $size in $spacing-sizes {
33 .#{$typeKey}x-#{$sizeKey} {
34 #{$type}-left: $size * $spacing-base-size;
35 #{$type}-right: $size * $spacing-base-size;
36 }
37 }
38
39 // my-1{marfin-top:10px;marfin-bottom:10px} || py-5{padding-top:50px;padding-bottom:50px;}
40 @each $sizeKey, $size in $spacing-sizes {
41 .#{$typeKey}y-#{$sizeKey} {
42 #{$type}-top: $size * $spacing-base-size;
43 #{$type}-bottom: $size * $spacing-base-size;
44 }
45 }
46 // mt-1 { margin-top: 10px } || pb-5{paddding-bottom:50px;}||ml-2{margin-left:20px}||pr-4{padding-right:40px}
47 @each $directionsKey, $directions in $spacing-directions {
48 @each $sizeKey, $size in $spacing-sizes {
49 .#{$typeKey}#{$directionsKey}-#{$sizeKey} {
50 #{$type}-#{$directions}: $size * $spacing-base-size;
51 }
52 }
53 }
54 }
使用的时候,在main.js文件内引用,
然后直接在 标签的 class 里面添加 对应类名 就可以
例如:
<div class="ml-5">现在就有左外边距50px</div>
<div class="pb-4">现在就有下内边距40px</div>
1 // flex布局
2 //类名 .flex-center-center
3 $justify:(
4 left:flex-start,
5 center:center,
6 right:flex-end,
7 between:space-between,
8 around:space-around
9 );
10 $align:(
11 top:flex-start,
12 center:center,
13 bottom:flex-end
14 );
15 @each $alignKey,$alignVal in $align{
16 @each $justifyKey,$justifyVal in $justify{
17 .flex-#{$justifyKey}-#{$alignKey}{
18 display: flex;
19 justify-content: #{$justifyVal};
20 align-items: #{$alignVal};
21 }
22 }
23 };
24
25
26 // 边框颜色
27 //类名 .border-b
28 $orientation:(
29 t:top,
30 b:bottom,
31 l:left,
32 r:right,
33 );
34 @each $orientationKey,$orientationVal in $orientation {
35 .border-#{$orientationKey}{
36 border-#{$orientationVal}:1px solid #E4E4EE;
37 }
38 }