Compass學(xué)習(xí)小結(jié)

PS:本文基于SASS進(jìn)行陳述

What is Compass

Compass

簡單說,Compass是Sass的工具庫(toolkit)。
Sass本身只是一個(gè)編譯器绽快,Compass在它的基礎(chǔ)上,封裝了一系列有用的模塊和模板,補(bǔ)充Sass的功能粘驰。它們之間的關(guān)系,有點(diǎn)像Javascript和jQuery述么、Ruby和Rails蝌数、python和Django的關(guān)系。

Installation

安裝Compass的前提是你的電腦中已經(jīng)安裝了Ruby和Gem度秘,沒安裝顶伞?點(diǎn)我點(diǎn)我
題外話:建議將Gem的下載源更改為淘寶源,國內(nèi)的防火墻太牛逼了剑梳。傳送門
在終端輸入:

sudo gem install compass   //for Linus or Mac
gem install compass        //for Windows

Enter compass -v to ensure you install compass successfully.

Create Compass Project

First:

compass create myProject

Then you will get three items:


Three items after create
  1. config.rb
    important file, you will write configuration in this file.
  1. sass dictionary
    non-essential, the scss or sass source files in here.
  2. stylesheets dictionary
    non-essential, the css source files after compass compile are stored in here.

Some Compass Commands

In fact, in my opinion, just one command you might know:

compass watch

Compass will watch the scss source file automatically, if you modify the file , he will compile .scss file to .css file. So easy, right?
You must pay more attention in config.rb, maybe config.rb like this:

// in my own project, please config it by your own condition.
http_path = "/"
css_dir = "public/css-cache"
sass_dir = "sass"
images_dir = "public/img"
javascripts_dir = "public/js"

If you want know more commands, please visit official website. Click it

Compass modules

Why is Compass so powerful? Because Compass pack some useful inside modules. They can help you to write more effective css code with sass. Five inside modules in Compass,they are:

  • reset
  • css3
  • layout
  • typography
  • utilities

1. reset

It help you to reset html tag style. Call it like this:

// take it in the head of file
@import "compass/reset";

This code will load reset code automatically.

2. css3

Most useful modules.
In this modules,compass gives about 21 css3 commands.The official website gives some samples, you can see that.

For example, border-radius

@import "compass/css3";
.rounded {
  @include border-radius(5px);
}

After compass compile:

.rounded {
  -moz-border-radius: 5px;    
  -webkit-border-radius: 5px;    
  -o-border-radius: 5px;    
  -ms-border-radius: 5px;    
  -khtml-border-radius: 5px;    
  border-radius: 5px;
}

3.layout

This module provides layout function. No much issue to explain.

4.typography

This module provides format function.
For example , you can assign the format of a tag:

//link-colors($normal, $hover, $active, $visited, $focus);
@import "compass/typography";
a {
  @include link-colors(#00c, #0cc, #c0c, #ccc, #cc0);
}

5.utilities

Utility function.
For example, clearfix:

import "compass/utilities/";
.clearfix {
 @include clearfix;
}

Compass Sprite(用compass制作雪碧圖)

The detail

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末唆貌,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子垢乙,更是在濱河造成了極大的恐慌锨咙,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,826評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件追逮,死亡現(xiàn)場離奇詭異酪刀,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)钮孵,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評論 3 395
  • 文/潘曉璐 我一進(jìn)店門骂倘,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人油猫,你說我怎么就攤上這事稠茂。” “怎么了情妖?”我有些...
    開封第一講書人閱讀 164,234評論 0 354
  • 文/不壞的土叔 我叫張陵睬关,是天一觀的道長。 經(jīng)常有香客問我毡证,道長电爹,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,562評論 1 293
  • 正文 為了忘掉前任料睛,我火速辦了婚禮丐箩,結(jié)果婚禮上摇邦,老公的妹妹穿的比我還像新娘。我一直安慰自己屎勘,他們只是感情好施籍,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,611評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著概漱,像睡著了一般丑慎。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上瓤摧,一...
    開封第一講書人閱讀 51,482評論 1 302
  • 那天竿裂,我揣著相機(jī)與錄音,去河邊找鬼照弥。 笑死腻异,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的这揣。 我是一名探鬼主播悔常,決...
    沈念sama閱讀 40,271評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼曾沈!你這毒婦竟也來了这嚣?” 一聲冷哼從身側(cè)響起鸥昏,我...
    開封第一講書人閱讀 39,166評論 0 276
  • 序言:老撾萬榮一對情侶失蹤塞俱,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后吏垮,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體障涯,經(jīng)...
    沈念sama閱讀 45,608評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,814評論 3 336
  • 正文 我和宋清朗相戀三年膳汪,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了唯蝶。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,926評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡遗嗽,死狀恐怖粘我,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情痹换,我是刑警寧澤征字,帶...
    沈念sama閱讀 35,644評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站娇豫,受9級特大地震影響匙姜,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜冯痢,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,249評論 3 329
  • 文/蒙蒙 一氮昧、第九天 我趴在偏房一處隱蔽的房頂上張望框杜。 院中可真熱鬧,春花似錦袖肥、人聲如沸咪辱。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽梧乘。三九已至,卻和暖如春庐杨,著一層夾襖步出監(jiān)牢的瞬間选调,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評論 1 269
  • 我被黑心中介騙來泰國打工灵份, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留仁堪,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,063評論 3 370
  • 正文 我出身青樓填渠,卻偏偏與公主長得像弦聂,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子氛什,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,871評論 2 354

推薦閱讀更多精彩內(nèi)容