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
170
Other Decks in Technology
See All in Technology
Terraformを用いたJamf Pro構成のIaC, GitOps化への挑戦
yukun
0
110
【Findyテック文化祭ワークショップ】新卒エンジニア&採用担当と作る、 なりたい姿と今やるべき一歩
dip_tech
PRO
0
150
Swap and Memory Reclaim - Squeezing Out More RAM
ennael
PRO
1
1.3k
行動するAIのためのオントロジー | DevRev — Encraft #26.pdf
dvrv_tknrszk
1
600
PQC移行の今 -- IETF からみた現在地
satokan
4
660
AIエージェント時代のPlatform as a Product —— テックリードがPdMとして回す発見・導入・計測 / Platform as a Product in the AI Agent Era
toshi0607
1
530
Harness Engineering on Rails
joelq
0
760
The kernel report
ennael
PRO
1
140
AWS DevOps Agent スキルをつかいこなそう / Master AWS DevOps Agent Skills
kinunori
2
640
Account Factory for Terraformによる 標準化されたアカウント発行の自動化
pensuke628
0
120
Databricksメトリクスビューはじめてのもくもく会
taka_aki
0
140
IR Today: Theory, Practice, and Agents
dtunkelang
0
250
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
How to train your dragon (web standard)
notwaldorf
97
6.8k
Evolving SEO for Evolving Search Engines
ryanjones
0
300
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
270
Making Projects Easy
brettharned
120
6.8k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
The untapped power of vector embeddings
frankvandijk
2
1.9k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
510
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
330
So, you think you're a good person
axbom
PRO
2
2.2k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
530
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