Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SASS & Compass 101
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
LucienLee
November 11, 2014
Technology
320
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
88
final album
lucienlee
0
79
Simple Album
lucienlee
0
110
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
340
Start to Build your Web
lucienlee
1
440
既然如此,那我們來hack資本世界吧!
lucienlee
0
160
Other Decks in Technology
See All in Technology
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
5
1.8k
HHKBエバンジェリストになる方法
941
0
110
作って終わりじゃないサーバーレス 〜9年運用する大規模EC物流API基盤の設計・運用のリアル〜
zozotech
PRO
0
160
Vibe Coding で作ったプロダクトをどう安全に動かすか / How to Safely Run Products Built with Vibe Coding
glidenote
0
150
株式会社シーエーシー エンジニア向け会社紹介資料
cac
0
57k
AIで社員の自主発信に広報目線を組み込む
_mossann_t
0
130
バイブコーディング時代のWebアプリ開発入門~Cloud Runで学ぶセキュアなビルドとデプロイ
waiwai2111
1
140
CLIライブラリ開発を支える技術
htnabe
0
130
LLMに渡さなかった仕事
nanaism
0
790
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
2.1k
Azure Serverless 2026:Production-ready な AI エージェント基盤 / Azure Serverless 2026: Production-Ready AI Agent Platform
miyake
2
210
Cloudflare Workers 向けアプリを C# で構築する ~WASM Native AOT への道~
nenonaninu
1
300
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
For a Future-Friendly Web
brad_frost
183
10k
Documentation Writing (for coders)
carmenintech
77
5.5k
Ruling the World: When Life Gets Gamed
codingconduct
0
330
ラッコキーワード サービス紹介資料
rakko
1
4.9M
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
670
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
890
Exploring anti-patterns in Rails
aemeredith
4
510
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
The Curious Case for Waylosing
cassininazir
1
510
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