Sass 中文网
Sass 用法指南 阮一峰
Scss 学习指南
Scss 基本使用
uniapp 添加scss全局变量、scss公共类
Scss 中的指令@import、@media、@extend 继承、@mixin、@include
Sass 函数:Sass Maps 的函数-map-get(
m
a
p
,
map,
map,key)
Sass Maps 的函数-map-keys($map)
Scss 在线转换器
Sass 就是 css 的预处理器,Scss 是 Sass3 版本中引入的新语法特性
HBuilder 要下载 “scss/sass 编译” 插件
对 uniapp 来说:
/* index.scss */
@import "./xxx/1.scss";
@import "./xxx/2.scss";
@import "./xxx/3.scss";
<style lang="scss">
@import "./xxx/yyy.scss";
style>
!default 可以添加在变量的结尾
!global 可以将变量提升为全局变量。
$side: bottom;
$font-color: #000;
$font-color: #999; !dafault;
.xxx {
color: $font-color;
border-#{$side}: 2px solid #999; /* 镶嵌在字符串的变量 */
}
$font-color: #000;
.xxx {
color: $font-color;
.yyy {
&:hover {
color: #fff;
}
}
}
通常会有两个类选择器的样式基本相同,第二个只是比第一个选择器多点样式,
原来的方案要么写两遍,要么在一个html标签上写两个选择器。
.xxx {
@extend .yyy;
}
.yyy {
color: #fff;
}
@mixin xxx {
color: #fff;
}
.yyy {
@include xxx;
}
@mixin xxx($font-color) {
color: $font-color;
}
.yyy {
@include xxx(#000);
}
@mixin xxx($font-color: #999) {
color: $font-color;
}
.yyy {
@include xxx();
}
.zzz {
@include xxx(#000);
}
.xxx {
@if 1==2 {
color: #999;
} @else if 3>5 {
color: #666;
} @else {
color: #000;
}
}
@for $i from 1 to 10 {
.border-#{$i} {
border: #{$i}px solid blue;
}
}
$i: 6;
@while $i > 0 {
.item-#{$i} { width: 2em * $i; }
$i: $i - 2;
}
@each $member in a, b, c, d {
.#{$member} {
background-image: url("/image/#{$member}.jpg");
}
}
@function double($n) {
@return $n * 2;
}
.xxx {
font-size: double(20px);
}
color: lighten(green, 10%); /* 表示绿色变浅10% */
color: darken(green, 10%); /* 表示绿色加深10% */
媒体查询可以放在选择器里边
.sidebar {
width: 300px;
@media screen and (orientation: landscape) {
width: 500px;
}
}
相同前缀属性可以简写
/* css */
.large-text {
font-family: Arial;
font-size: 20px;
font-weight: bold;
}
/* scss */
.large-text {
font: {
family: Arial;
size: 20px;
weight: bold;
}
}
/*!
重要注释!
*/