提示:初学者谨慎使用,不利于打好基础
一、在src下面创一个base.scss文件?
二、使用步骤
1.写入常用的css
//主题色
$color :(
black:#333,
black1:#666,
black2:#999,
gray:#DCDCDC,
white:white,
red:#ff3d3d,
blue:#298def,
yellow:#ffa800,
green:#2bbb9a,
);
//背景色
@each $k,$v in $color {
.bg-#{$k} {
background: {
color: $v;
};
}
}
-------------------------------------------------------------
//flex布局
$line:(
jc:justify-content,
ai:align-items,
ac:align-content
);
$dir:(
a:space-around,
b:space-between,
c:center,
e:flex-end,
s:flex-start
);
$dir_self:(
c:center,
e:flex-end,
s:flex-start
);
@each $k,$v in $line {
@each $a,$b in $dir {
.#{$k}-#{$a} {
#{$v}:$b
}
}
}
@each $k,$v in $dir_self {
.as-#{$k} {
align-self: $v;
}
}
---------------------------------------------------------
//某个单边框
@each $x,$m in $content_dir {
@each $y,$n in $color {
.b#{$x}-#{$y} {
border-#{$m}:53px solid $n
}
}
}
//所有边框
@each $a,$b in $color {
.b-#{$a} {
border: 53px solid $b;
}
}
--------------------------------------------------------
//字体
$level:(
1:0.25,
2:0.8,
3:1,
4:1.5,
5:2,
6:3
);
//字体大小
@each $key,$val in $level {
.rem#{$key} {
font-size: #{$val}rem;
}
}
$direction:(
l:left,
r:right,
c:center
);
//字体方向
@each $k,$v in $direction {
.t-#{$k} {
text-align: $v;
}
}
//字体颜色
@each $k,$v in $color {
.#{$k} {
color: $v;
}
}
---------------------------
//方向
$direction:( l:left, r:right, t:top,b:bottom);
//方式
$mapa:(m:margin, p:padding);
//大小
$size:( 1:0.125, 2:0.25, 3:0.375);
@each $k,
$v in $mapa {
@each $a,
$b in $direction {
@each $m,
$n in $size {
.#{$k}#{$a}-#{$m} {
#{$v}-#{$b}: #{$n}rem;
}
}
}
}
2.main.js(入口文件)
require('./assets/base.scss')//路劲仅供参考
3.在任意页面的使用
<div class="black">颜色是#333333</div>
<div class="bg-black">背景颜色是#333333</div>
<div class="jc-b">flex布局中justify-content:space-between</div>
<div class="rem1">字体大小是0.25rem</div>
<div class="t-l">字体方向text-align:left</div>
<div class="ml-2">盒子有个margin-left:0.25rem 边距</div>
<div class="f jc-b bold xxx xxx xxxx xxx">
长期使用后在遇面试官问:盒子居中 jc-c 卧槽记不得了...............
</div>
总结
还是开头那句话,谨慎使用。还会有node版本问题导致的sass报错问题,不过版本问题都很好解决。