1.自定義變量css
$color:pink; .test1{ background-color:$color; }
經過編譯工具編譯出來後app
.test1{ background-color:pink; }
注:時間緣由我在這裏只寫scss了,就不寫編譯後的結果,一來方便你們本身去嘗試編譯,二來增長你們對scss的理解:編譯工具kaola很好的一個編譯工具,你們能夠百度如何使用,再這裏就不作過多介紹了。
***
2.插入一個變量koa
$right:right; .test2{ border-#{$right}:1px solid #000; }
3.子元素書寫函數
.text3{ .text33{ border:1px solid; } }
4.樣式的加減乘除工具
$paramer:3; .text4{ height:(1px+3px); width: (96px/6); right: $paramer*4; }
5.繼承url
.class5{ border:1px solid red; } .class5E{ @extend .class5; font-size:20px; }
6.代碼塊的複用code
@mixin text6 { height:50px; left:20px; } .text6M{ @include text6 } //這裏的mixin就是定義一個能夠複用的代碼段,固然咱們也能夠給它傳遞一個參數,就像這樣同樣: @mixin text66($height){ height:$heigth; left:20px; } .text6N{ @include text66(100px); }
7.if語法,經過對if的判斷來決定使用那一套樣式繼承
.text7{ @if 1 +2 == 3 { border:1px solid ; } @if 5 < 3 { border:2px dsahed red; } } 固然,咱們都知道if通常是要和else配合的,因此咱們也能夠這樣寫 .test77{ @if lightness($color) > 30%{ background-color:#fff; }@else{ background:#0ff; } } 這裏的lightness是一個scss顏色函數,$color指向以前定義的值。
8.循環語法,包括最多見的三種循環方法,for,while,each開發
//for 循環 @for $i from 1 to 5 { .item-#{$i} { border:#{$i}px solid; } } //while 循環 $m:8; @while $m > 0 { .items-#{$m} { width:2em*$m; } $m:$m - 2 ; } //這裏能夠對$m進行運算 讓它每次都減去2 //each 語法 @each $img in q,w,e,r { .#{$img} { background-image:url('#{$img}.png') } }
9.函數語法get
@function double ($number){ @return $number*2; } .text9{ font-size:double(20px); }
10.import導入語法
@import 'other.scss' 這樣就在你如今的scss中導入了other.scss編寫的scss