sass初級文法,sass

來源:互聯網
上載者:User

sass初級文法,sass

用到的sass文法是:

sass --watch test.scss:test.css --style compact --style expanded

如:


1 自訂變數

test.scss內容是:

$color: black;.test1 {    background-color: $color;} 

編譯成test.css內容是:

.test1 {  background-color: black;}

 

2 在字串內加變數

test.scss內容是:

$left: left;.test2 {    border-#{$left}:1px  #000 solid;}

編譯成test.css內容是:

.test2 {  border-left: 1px  #000 solid;}

 

3 樣式內進行加減乘除(注意除法書寫)

test.scss內容是:

$para:4;.test3 {    height: 5px+3px;    width: (14px/7);    right: $para*4;}

編譯成test.css內容是:

.test3 {  height: 8px;  width: 2px;  right: 16;}

 

4 子項目書寫

test.scss內容是:

.test4 {    .lala {        color: pink;    }}

編譯成test.css內容是:

.test4 .lala {  color: pink;}

 

5 繼承(SASS允許一個選取器,繼承另一個選取器)

test.scss內容是:

.class1 {    border-left: 1px #000 solid;}.class2 {    @extend .class1;    font-size: 15px;}

編譯成test.css內容是:

.class1, .class2 {  border-left: 1px #000 solid;}.class2 {  font-size: 15px;}

 

6 複用代碼塊

test.scss內容是:(無變數)

@mixin test6 {    height: 5px;    left: 20px;    top: 10px;}.lili {    @include test6;}

編譯成test.css內容是:(無變數)

.lili {  height: 5px;  left: 20px;  top: 10px;}

這個方法很好用的是可以設定變數,如下:

test.scss內容是:(有變數)

@mixin test62($height) {    height: $height;    left: 20px;    top: 10px;}.lili2 {    @include test62(100px);}

編譯成test.css內容是:(有變數)

.lili2 {  height: 100px;  left: 20px;  top: 10px;}

 

7 函數

test.scss內容是:

@function aa($color) {    @return $color;}.test7 {    color: aa(pink);}

編譯成test.css內容是:

/*example 07*/.test7 {  color: pink;}

 

8 匯入外部scss或者css檔案

test.scss內容是:

@import 'more.scss' 

more.scss內容是:

$width: 30px;.test8 {    width: $width;}

編譯成test.css內容是:

.test8 {  width: 30px;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.