企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# sass 变量声明 `$color:#FFFFFF;``$fancybox-width: 400px !default;` 嵌套 ``` <pre class="calibre14">``` #id <span class="token2">{</span> h1<span class="token2">{</span>color<span class="token2">:</span>#<span class="token3">000000</span><span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>red<span class="token2">{</span>background<span class="token2">:</span> #<span class="token3">8</span>F8F94<span class="token2">;</span>font<span class="token">-</span>size<span class="token2">:</span> <span class="token3">14</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">}</span> #id h1<span class="token2">{</span>color<span class="token2">:</span>#<span class="token3">000</span><span class="token2">}</span> #id <span class="token2">.</span>red<span class="token2">{</span>background<span class="token2">:</span>#<span class="token3">8</span>f8f94<span class="token2">;</span>font<span class="token">-</span>size<span class="token2">:</span><span class="token3">14</span>px<span class="token2">}</span> ``` ``` 父选择器标识符 & ``` <pre class="calibre14">``` article a <span class="token2">{</span> color<span class="token2">:</span> blue<span class="token2">;</span> <span class="token">&</span><span class="token2">:</span>hover <span class="token2">{</span> color<span class="token2">:</span> red <span class="token2">}</span> <span class="token2">}</span> article a<span class="token2">{</span>color<span class="token2">:</span>#<span class="token3">00</span>f<span class="token2">}</span> article a<span class="token2">:</span>hover<span class="token2">{</span>color<span class="token2">:</span>red<span class="token2">}</span> ``` ``` 群组嵌套 ``` <pre class="calibre14">``` <span class="token2">.</span>container <span class="token2">{</span> h1<span class="token2">,</span> h2<span class="token2">,</span> h3 <span class="token2">{</span>margin<span class="token">-</span>bottom<span class="token2">:</span> <span class="token3">.8</span>em<span class="token2">}</span> <span class="token2">}</span> <span class="token2">.</span>container h1<span class="token2">,</span> <span class="token2">.</span>container h2<span class="token2">,</span> <span class="token2">.</span>container h3 <span class="token2">{</span> margin<span class="token">-</span>bottom<span class="token2">:</span> <span class="token3">.8</span>em<span class="token2">;</span> <span class="token2">}</span> ``` ``` 属性嵌套 ``` <pre class="calibre14">``` nav <span class="token2">{</span> border<span class="token2">:</span> <span class="token3">1</span>px solid #ccc <span class="token2">{</span> left<span class="token2">:</span> <span class="token3">0</span>px<span class="token2">;</span> right<span class="token2">:</span> <span class="token3">0</span>px<span class="token2">;</span> <span class="token2">}</span> <span class="token2">}</span> nav <span class="token2">{</span> border<span class="token2">:</span> <span class="token3">1</span>px solid #ccc<span class="token2">;</span> border<span class="token">-</span>left<span class="token2">:</span> <span class="token3">0</span>px<span class="token2">;</span> border<span class="token">-</span>right<span class="token2">:</span> <span class="token3">0</span>px<span class="token2">;</span> <span class="token2">}</span> ``` ``` 导入style.scss文件 `@import "style"` 混合器 ``` <pre class="calibre14">``` @mixin rounded<span class="token">-</span>corners <span class="token2">{</span> <span class="token">-</span>moz<span class="token">-</span>border<span class="token">-</span>radius<span class="token2">:</span> <span class="token3">5</span>px<span class="token2">;</span> <span class="token">-</span>webkit<span class="token">-</span>border<span class="token">-</span>radius<span class="token2">:</span> <span class="token3">5</span>px<span class="token2">;</span> border<span class="token">-</span>radius<span class="token2">:</span> <span class="token3">5</span>px<span class="token2">;</span> <span class="token2">}</span> @mixin <span class="token1">test</span><span class="token2">(</span>$b<span class="token2">:</span><span class="token3">0</span><span class="token2">)</span><span class="token2">{</span> <span class="token2">.</span>margin#<span class="token2">{</span>$b<span class="token2">}</span><span class="token">-</span>t<span class="token2">{</span>margin<span class="token">-</span>top<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>margin#<span class="token2">{</span>$b<span class="token2">}</span><span class="token">-</span>r<span class="token2">{</span>margin<span class="token">-</span>right<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>margin#<span class="token2">{</span>$b<span class="token2">}</span><span class="token">-</span>b<span class="token2">{</span>margin<span class="token">-</span>bottom<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>margin#<span class="token2">{</span>$b<span class="token2">}</span><span class="token">-</span>l<span class="token2">{</span>margin<span class="token">-</span>left<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>margin#<span class="token2">{</span>$b<span class="token2">}</span><span class="token2">{</span>margin<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>padding#<span class="token2">{</span>$b<span class="token2">}</span><span class="token">-</span>t<span class="token2">{</span>padding<span class="token">-</span>top<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>padding#<span class="token2">{</span>$b<span class="token2">}</span><span class="token">-</span>r<span class="token2">{</span>padding<span class="token">-</span>right<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>padding#<span class="token2">{</span>$b<span class="token2">}</span><span class="token">-</span>b<span class="token2">{</span>padding<span class="token">-</span>bottom<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>padding#<span class="token2">{</span>$b<span class="token2">}</span><span class="token">-</span>l<span class="token2">{</span>padding<span class="token">-</span>left<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">.</span>padding#<span class="token2">{</span>$b<span class="token2">}</span><span class="token2">{</span>padding<span class="token2">:</span>#<span class="token2">{</span>$b<span class="token2">}</span>px<span class="token2">;</span><span class="token2">}</span> <span class="token2">}</span> <span class="token2">.</span>notice <span class="token2">{</span> @include rounded<span class="token">-</span>corners<span class="token2">;</span> <span class="token2">}</span> @mixin <span class="token1">qq</span><span class="token2">(</span>$a<span class="token2">:</span><span class="token3">1</span><span class="token2">,</span>$b<span class="token2">)</span><span class="token2">{</span> <span class="token6">//支持默认值或外部变量</span> <span class="token2">}</span> ``` ``` 继承 ``` <pre class="calibre14">``` <span class="token2">.</span>error <span class="token2">{</span> border<span class="token2">:</span> <span class="token3">1</span>px solid red<span class="token2">;</span> background<span class="token">-</span>color<span class="token2">:</span> #fdd<span class="token2">;</span> <span class="token2">}</span> <span class="token2">.</span>seriousError <span class="token2">{</span> @extend <span class="token2">.</span>error<span class="token2">;</span> border<span class="token">-</span>width<span class="token2">:</span> <span class="token3">3</span>px<span class="token2">;</span> <span class="token2">}</span> ``` ``` 插值语句 ``` <pre class="calibre14">``` #<span class="token2">{</span>$name<span class="token2">}</span> ``` ``` ``` <pre class="calibre14">``` @<span class="token5">for</span> $i from <span class="token3">1</span> through <span class="token3">3</span> <span class="token2">{</span> <span class="token2">.</span>item<span class="token">-</span>#<span class="token2">{</span>$i<span class="token2">}</span> <span class="token2">{</span> width<span class="token2">:</span> <span class="token3">2</span>em <span class="token">*</span> $i<span class="token2">;</span> <span class="token2">}</span> <span class="token2">}</span> <span class="token2">.</span>item<span class="token">-</span><span class="token3">1</span><span class="token2">{</span>width<span class="token2">:</span><span class="token3">2</span>em<span class="token2">}</span><span class="token2">.</span>item<span class="token">-</span><span class="token3">2</span><span class="token2">{</span>width<span class="token2">:</span><span class="token3">4</span>em<span class="token2">}</span><span class="token2">.</span>item<span class="token">-</span><span class="token3">3</span><span class="token2">{</span>width<span class="token2">:</span><span class="token3">6</span>em<span class="token2">}</span> ``` ``` ``` <pre class="calibre16">``` @each $animal <span class="token5">in</span> puma<span class="token2">,</span> sea<span class="token">-</span>slug<span class="token2">,</span> egret<span class="token2">,</span> salamander <span class="token2">{</span> <span class="token2">.</span>#<span class="token2">{</span>$animal<span class="token2">}</span><span class="token">-</span>icon <span class="token2">{</span> background<span class="token2">:</span>#<span class="token3">008000</span><span class="token2">;</span> <span class="token2">}</span> <span class="token2">}</span> <span class="token2">.</span>puma<span class="token">-</span>icon<span class="token2">{</span>background<span class="token2">:</span>green<span class="token2">}</span><span class="token2">.</span>sea<span class="token">-</span>slug<span class="token">-</span>icon<span class="token2">{</span>background<span class="token2">:</span>green<span class="token2">}</span><span class="token2">.</span>egret<span class="token">-</span>icon<span class="token2">{</span>background<span class="token2">:</span>green<span class="token2">}</span><span class="token2">.</span>salamander<span class="token">-</span>icon<span class="token2">{</span>background<span class="token2">:</span>green<span class="token2">}</span> ``` ```