學(xué)習(xí)筆記《Sass》

最近一直被各種安利 Sass 的使用,正好 Laravel5.3 也已經(jīng)高度集成,所以剛好學(xué)習(xí),Wikipedia 上對于 Sass 的定義:

Sass (Syntactically Awesome Stylesheets) is a style sheet language initially designed by Hampton Catlin and developed by Natalie Weizenbaum. After its initial versions, Weizenbaum and Chris Eppstein continued to extend Sass with SassScript, a simple scripting language used in Sass files.

Hampton Catlin 也是 Haml 語法的設(shè)計(jì)者,Natalie Weizenbaum 則是一位 Google 的工程師,正在為 Google 改進(jìn) Dart 語言

Sass 是一套 CSS 的編寫規(guī)則,然后經(jīng)過工具的編譯可以成為瀏覽器可以識別的 CSS 文件,Sass 發(fā)源于 Ruby 社區(qū),最開始是基于 Ruby 做的實(shí)現(xiàn),現(xiàn)在已經(jīng)轉(zhuǎn)向了 C/C++ 實(shí)現(xiàn)的 LibSass,Laravel 默認(rèn)是選擇用 nodejs 的 node-sass( gulp 基于 node-sass,node-sass 基于 LibSass):
https://github.com/gulpjs/gulp
https://github.com/sass/node-sass
https://github.com/sass/libsass

目前 Sass 最新版本是 3.4.22,從維護(hù)頻率上來看已經(jīng)相當(dāng)穩(wěn)定了,3.5 版本和 4 版本也都在緊鑼密鼓中

導(dǎo)入:

@import "reset.css";

變量:

$fontSize: 12px;
body{
    font-size:$fontSize;
}

嵌套:

#top_nav{
  line-height: 40px;
  text-transform: capitalize;
  background-color:#333;
  li{
    float:left;
  }
  a{
    display: block;
    padding: 0 10px;
    color: #fff;

    &:hover{
      color:#ddd;
    }
  }
}

嵌套可以把以前一長串的 CSS 名字,使用更直觀的層次感表現(xiàn)出來

混合:

@mixin horizontal-line($border:1px dashed #ccc, $padding:10px){
  border-bottom:$border;
  padding-top:$padding;
  padding-bottom:$padding;  
}
.imgtext-h li{
  @include horizontal-line(1px solid #ccc);
}
.imgtext-h--product li{
   @include horizontal-line($padding:15px);
}

一種看似函數(shù)的形式,來對重復(fù)性的內(nèi)容進(jìn)行簡化

繼承:

h1{
  border: 4px solid #ff9aa9;
}
.speaker{
  @extend h1;
  border-width: 2px;
}

函數(shù):

// pixels to rems 
@function pxToRem($px) {
  @return $px / $baseFontSize * 1rem;
}

body{
  font-size:$baseFontSize;
  color:lighten($gray,10%);
}
.test{
  font-size:pxToRem(16px);
  color:darken($gray,10%);
}

運(yùn)算:

$baseFontSize:          14px !default;
$baseLineHeight:        1.5 !default;
$baseGap:               $baseFontSize * $baseLineHeight !default;
$halfBaseGap:           $baseGap / 2  !default;
$samllFontSize:         $baseFontSize - 2px  !default;

條件判斷及循環(huán):

$lte7: true;
$type: monster;
.ib{
  display:inline-block;
  @if $lte7 {
    *display:inline;
    *zoom:1;
  }
}
p {
  @if $type == ocean {
    color: blue;
  } @else if $type == matador {
    color: red;
  } @else if $type == monster {
    color: green;
  } @else {
    color: black;
  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、什么是sass css預(yù)處理器,它的基本思想是:用一種專門的編程語言,進(jìn)行網(wǎng)頁樣式設(shè)計(jì),然后再編譯成正常的cs...
    質(zhì)真如渝閱讀 620評論 0 1
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,892評論 2 45
  • 記憶的深處有一條小河 河水常常流進(jìn)夜里 伙同魚蝦、兒時(shí)玩伴一同進(jìn)入夢鄉(xiāng) 河邊青青草、野花和蝴蝶 也來趕熱鬧 游的游...
    蕙蘭漱雪閱讀 288評論 7 16
  • 花好月圓夜,閨中待郎君 時(shí)間還尚早,倚窗望出神 半寐半醒間,忽聞急敲門 忙施粉黛色,應(yīng)是赴約人
    flyeek閱讀 192評論 0 0
  • 我很想認(rèn)認(rèn)真真的喜歡一個(gè)人 想——從一而終 我想跟他念同一所高中、大學(xué) 可現(xiàn)實(shí)哪會那么的美好 還沒等我跟他當(dāng)面告白...
    會長思念閱讀 226評論 0 0

友情鏈接更多精彩內(nèi)容