Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SASS & Compass 101
Search
LucienLee
November 11, 2014
Technology
310
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SASS & Compass 101
LucienLee
November 11, 2014
More Decks by LucienLee
See All by LucienLee
Use PaaS service to host your web - with pagodabox
lucienlee
0
86
final album
lucienlee
0
78
Simple Album
lucienlee
0
100
Accessing MySQL from PHP
lucienlee
1
380
DataBase and MySQL
lucienlee
1
240
PHP 101+1:function & form
lucienlee
1
300
PHP 101: flow control
lucienlee
0
330
Start to Build your Web
lucienlee
1
440
既然如此,那我們來hack資本世界吧!
lucienlee
0
160
Other Decks in Technology
See All in Technology
AIのReact習熟度を測る
uhyo
2
690
事業会社における 機械学習・推薦システム技術の活用事例と必要な能力 / ml-recsys-in-layerx-wantedly-2026
yuya4
0
160
Lightning近況報告
kozy4324
0
220
AWS Security Agent といっしょに脅威モデリングをやってみよう
amarelo_n24
1
210
AIAU_UMEMOGU_ninomiya_slide
ninomiya_ii
0
260
コミュニティの有益性 ~JAWS Days 2026 での体験を通して~ / The Benefits of a Community ~Through My Experience at JAWS Days 2026~
seike460
PRO
0
280
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
11k
BPaaSで進むAIオペレーションの現在地 AI実装が効く領域とスケーラビリティの選定と実装
kentarofujii
0
200
Zenoh on Zephyr on LiteX
takasehideki
2
110
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
210
フルAIで個人開発して学んだあれこれ / yuruai vol.1
isaoshimizu
0
130
【セミナー資料】Claude Code をセキュアに使うための考え方と設定の勘どころ / Claude Code Webinar 20260616
masahirokawahara
2
470
Featured
See All Featured
Site-Speed That Sticks
csswizardry
13
1.2k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
490
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
160
Scaling GitHub
holman
464
140k
Facilitating Awesome Meetings
lara
57
7k
30 Presentation Tips
portentint
PRO
1
330
New Earth Scene 8
popppiees
3
2.4k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
480
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Evolving SEO for Evolving Search Engines
ryanjones
0
220
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Transcript
請先⾄至 http://goo.gl/XFtR7l 下載 Prepros 並安裝到 C:\使⽤用者\student
SASS & COMPASS 資訊系統訓練班 246 期
今⽇日介紹 SASS (SCSS 檔) 更好寫的 CSS。 Compass 函式庫 套件管理 Bootstrap-sass
CSS 好多重複。
#top-bar { height: 92px; overflow: auto; } #top-bar h1{ width:
124px; height: 92px; background: url(../images/logo.png) center center no-repeat; color: transparent; font: 0/0 a; text-shadow: none; float: left; } #top-bar ul{ margin: 53px 0 0 45px; float: left; list-style: none; }
.seriousError { border: 3px #f00; background-color: #fdd; } .inputError {
border: 1px #f00; background-color: #fdd; } .seriousError, .inputError { border-color: #f00; background-color: #fdd; } .seriousError { border-width: 3px; } .inputError { border-width: 1px; } 可能會忘記 .inputError 的樣式 在前⾯面曾經設定過
.shadows { -moz-box-shadow: 0px 4px 5px #666666, 2px 6px 10px
#999999; -webkit-box-shadow: 0px 4px 5px #666666, 2px 6px 10px #999999; box-shadow: 0px 4px 5px #666666, 2px 6px 10px #999999; } .shadows-invert { -moz-box-shadow: 0px -4px 5px #666666, 2px -6px 10px #999999; -webkit-box-shadow: 0px -4px 5px #666666, 2px -6px 10px #999999; box-shadow: 0px -4px 5px #666666, 2px -6px 10px #999999; }
SASS 兩種語法:SASS 與 SCSS (Sassy CSS) SCSS 語法為 CSS 的擴充。
SASS Nesting Variables @include @extend 附檔名:.scss
Variables (變數) $header-height: 40px; .header{ position: fixed; top: 0; left:
0; width: 100% height: $header-height; } .contents{ padding-top: $header-height; }
Nesting #top-bar { height: 92px; overflow: auto; h1{ width: 124px;
height: 92px; background: url(../images/logo.png); color: transparent; font: 0/0 a; text-shadow: none; float: left; } ul{ margin: 53px 0 0 45px; float: left; list-style: none; } } #top-bar { height: 92px; overflow: auto; } #top-bar h1{ width: 124px; height: 92px; background: url(../images/logo.png); color: transparent; font: 0/0 a; text-shadow: none; float: left; } #top-bar ul{ margin: 53px 0 0 45px; float: left; list-style: none; }
@extend .seriousError, .inputError { border-color: #f00; background-color: #fdd; } .seriousError
{ border-width: 3px; } .inputError { border-width: 1px; } %error { border-color: #f00; background-color: #fdd; } .seriousError { @extend %error; border-width: 3px; } .inputError { @extend %error; border-width: 1px; }
@include @mixin box-shadow($shadows...) { -moz-box-shadow: $shadows; -webkit-box-shadow: $shadows; box-shadow: $shadows;
} .shadows { @include box-shadow(0px 4px 5px #666, 2px 6px 10px #999); } .shadows-invert { @include box-shadow(0px -4px 5px #666, 2px -6px 10px #999); }
html 檔 css 檔 引⽤用 <link href=”......”> 很難寫 scss 檔
好寫 好讀 ⼩小結 轉換成 (編譯 / compile) 需 ruby 和⼀一些套件 Prepros 可以搞定這些!
PREPROS
Latest version is 5.1 Still have some bugs
Prepros 拖曳含有檔案的資料夾 “Project” ⾃自動 *.scss --> css/*.css
SCSS 練習時間
Hello world! $color: black; .hello-world{ color: $color; }
下載範例包 https://dl.dropboxusercontent.com/u/3813488/train/ hlb-scss.zip or http://bit.ly/hlb-sass
Variables 可以做加減乘除 variables_5.scss 顏⾊色變數有特殊 function 可以操作 color_1.scss
Nesting 基本 Nesting nested_1.scss “&”symbol nested_4.scss
@extend %placeholder 假的 Selector,名字不會出現在 CSS 裡。 extend_4.scss
@include @mixin 定義⼀一個 Mixin(類似函數的東⻄西) @include 來使⽤用 Mixin mixin_1.scss mixin_2.scss
COMPASS
html 檔 css 檔 引⽤用 <link href=”......”> 很難寫 scss 檔
好寫 好讀 架構 轉換成 (編譯 / compile) compass 函式庫 @import compass/...... 引⽤用
COMPASS 練習時間
Prepros 與 Compass Prepros 內建提供 Compass 勾選過後 要移除專案 重新新增專案
CSS3 @import "compass"; .box { @include border-radius(8px); @include box-shadow( rgba(#ccc,
0.5) 3px 3px 5px ); } .box { -webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; border-radius: 8px; -webkit-box-shadow: rgba(204, 204, 204, 0.5) 3px 3px 5px; -moz-box-shadow: rgba(204, 204, 204, 0.5) 3px 3px 5px; box-shadow: rgba(204, 204, 204, 0.5) 3px 3px 5px; } css3_3.scss
clearfix @import "compass"; section { @include clearfix; } .evil {
@include pie-clearfix; } section { overflow: hidden; *zoom: 1; } .evil { *zoom: 1; } .evil:after { content: ""; display: table; clear: both; } css3_1.scss
image-url 與路徑設定 http_path = "/" css_dir = "css" sass_dir =
"sass" images_dir = "images" javascripts_dir = "javascripts" fonts_dir = "fonts" config.rb 勾選過後 要移除專案 重新新增專案
為何要設定檔案路徑? Compass 可以找得到檔案 產⽣生正確路徑 + cache busting: image-url() 讀取圖⽚片寬⾼高 image-width()、image-height()
image-width/height 找⼀一張圖⽚片來試試!
BOOTSTRAP-SASS
BOOTSTRAP 的客製化
None
None
None
None
None
None
聰明些的辦法
參數設定 Bootstrap 樣式 ⾃自定樣式 Bootstrap 融合 編譯(?)
BOOTSTRAP-SASS 需要 套件 Prepros 內建沒有裝此套件 QQ 但 Prepros 可以讓我們⽤用⾃自⼰己的套件庫!
來裝 RUBY 與套件吧
更多名詞 Ruby 某程式語⾔言,scss 編譯器⽤用 Ruby 寫。 .scss 需要 Ruby 才能轉換成
css。 gem Ruby 的套件管理程式
安裝 Ruby (Windows) Ruby Installer ⼀一直按下⼀一步 從開始功能表找到 Start Command Prompt
with Ruby 訓練班的電腦已經裝好了 Ruby
安裝 Ruby (其他OS) Mac:內建有 Ruby,⽤用內建的。 Ubuntu/Debian:推薦⽤用 rvm 安裝,但會 compile 很久
;趕時間可以⽤用 sudo apt-get install ruby
安裝套件 Windows:「開始」>「提⽰示命令字元」 Mac: Spotlight (右上⾓角放⼤大鏡) > 終端機 打「gem install compass
bootstrap-sass」 安裝 compass, bootstrap-sass。 SASS 會被⼀一併安裝。 Mac 指令前⾯面要加上 sudo
範例執⾏行結果
設定 Prepros 使⽤用⾃自定 Ruby Prepros 預設⽤用 Prepros ⾃自⼰己的 Ruby 我們裝的
Ruby 才有 bootstrap-sass
⽤用 bootstrap-sass 開專案 打開「Start command prompt with ruby」 compass create
專案名 -‐r bootstrap-‐sass -‐-‐using bootstrap 產⽣生 _variables.scss、styles.scss 以及基本的⺫⽬目錄結構 ⽂文件 https://github.com/twbs/bootstrap-sass 註:Homework 3 已經做過此步驟囉! 不 ⽤用做
開新 專案 不 ⽤用做
_variables.scss 套⽤用下⾯面 HTML,改 _variables.scss 看效果 http://getbootstrap.com/examples/carousel/
附錄:config.rb relative_assets: image_url、font_url 是否要 ⽤用相對路徑。 output_style: 四選⼀一: :nested, :expanded, :compact,
:compressed 完整⽂文件:http://compass-style.org/help/tutorials/configuration- reference/
附錄:Prepros 設定們 Sass Options > Use Compass 使⽤用 compass Sass
Options > Use Compass + Full Compass Support 為了在 config.rb 指定路徑和選項 Advanced Options > Use Custom Ruby 使⽤用⾃自⼰己裝的 gem (如 bootstrap_sass)
附錄:⾃自動重新整理
cannot load such file -- bootstrap-sass 解法: 1. 確認有指定 ruby
2. 確認有 gem install bootstrap-sass
特別感謝 薛良斌前輩 (hlb) 提供 SCSS 範例 https://gist.github.com/hlb/6076665 http://iamhlb.com/about