Compass Base 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 @import  "reset/utilities" ;
@include global -reset ;
a { @include link -colors (#333 , #00 f, #f00 , #555 , #f00 ); }
a { @include link -colors (
  #333 ,
  $hover : #00 f,
  $active : #f00 ,
  $visited : #555 ,
  $focus : #f00 );
}
a {@include hover-link }
p. secret a,
p. secret a:hover,
p. secret a:focus {
color: inherit;
cursor: inherit;
text-decoration : inherit
}
p. secret a { @include unstyled-link  }
ul. features {
  @include pretty-bullets ('pretty-bullet.png' ,
    $padding : 10 px,
    $line -height : 22 px)
}
ul. no-bullet  { @include no-bullets }
li. no-bullet  { @include no-bullet  }
ul. nav { @include horizontal-list  }
ul. words { @include delimited-list ("! " ) }
td. dot-dot -dot  {
  @include ellipsis;
  }
td { @include nowrap }
h1. coffee { @include replace-text ("coffee-header.png" ) }
 
 
Layout helpers 
1
2
3
4
5
6
 @import  "compass/layout" ;  .
@include  sticky-footer (40 px, "#content" , "#footer" , "#sticky-footer" ); 
a .login  { @include  stretch (5 px, 5px , 5px , 5px ) } 
 
CSS3 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 @import  "compass/css3" ; 
$experimental-support-for-opera: false; 
$experimental-support-for-microsoft: false; 
$experimental-support-for-khtml: false; 
.notice  {
  @include  border-radius (5 px); 
}
.h2  {
  @include  box-shadow (#ccc  5px  5px  2px ); 
  text-shadow : #ddd  -1 px 1 px 0 ; 
  background : #999 ; 
  padding : 1 em; 
}
.motion  {
  @include  text-shadow (
   rgba (#000 ,.5 ) -200px  0  0 ,
   rgba (#000 ,.4 ) -400px  0  0 ,
   rgba (#000 ,.3 ) -600px  0  0 ,
   rgba (#000 ,.2 ) -800px  0  0 
  ); 
  font-size : 2 em; 
  font-style : italic; 
  text-align : right; 
}
  
@import  "compass" ; 
@include  font-face ("ChunkFiveRegular" ,
font-files ( "Chunkfive-webfont.woff" , woff ,
  "Chunkfive-webfont.ttf" , ttf ,
  "Chunkfive-webfont.svg" , svg ),
  "Chunkfive-webfont.eot" , normal , normal ); 
 
Support for Internet Explorer with CSS PIE 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
@import  "compass/css3/pie" ; 
.pie-element  {
  
  
  @include  pie-element (relative); 
}
.rounded  {
  @include  pie ; 
  @include  border-radius (20 px); 
}
.gradient  {
  @include  pie ; 
  @include  background (linear-gradient(#aaa, #333 ) ); 
}
 
 
Sprite 
https://github.com/Keyamoon/IcoMoon-limited 
<map> part is a placeholder and should be replaced with
the name of the folder containing your sprite images.
The all-sprites mixin will write all the necessary CSS
for the entire sprite map, whereas the second mixin will
output CSS for a single named sprite.
1
2
 @include  all-<map>-sprites ;
@include  <map>-sprite($name)  ;
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 @import  "compass/utilities/sprites" ;
@import  "icons/*.png" ;
@include all -icons -sprites ;
. add-button  { @extend . icons-box -add ; }
. add-button  {
  @include icons-sprite (box-add );
}
$< map >-< property> : setting;
$< map >-< sprite>-< property> : setting;
$icons -spacing : 4 px;
$icons -arrow -spacing :12 px;
$icons -arrow -repeat : repeat-x ;
$icons -position : 4 px;
$icons -arrow -position : 100 % ;
$< map >- layout: vertical/horizontal/diagonal/smart;
$icons -layout : smart;
$< map >- clean-up : true /false ;
 
 
Customizing the sprite CSS 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 @import  "icons/*.png" ;
. next {
  @include icons-sprite (arrow);
  width: icons-sprite -width (arrow);
  height: icons-sprite -height (arrow);
}
. add-button  {
  @include icons-sprite (box-add );
}
$< map >- sprite-dimensions : true /false ;
$disable -magic -sprite -selectors : true /false ;
 
 
Magic sprite selectors are enabled by default, meaning Compass will automatically
output CSS :hover , :active, and :target pseudo selectors for sprites
with names ending in _hover, _active, or _target.
You add arrow.png and arrow_hover.png to your sprite folder.
帮助函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 $icons : sprite-map ("icons/*. png" , $arrow -spacing: 5 px);
$icons : sprite-map ("icons/*. png" , $arrow -spacing: 5 px);
sprite($map , $sprite , [$offset -x ], [$offset -y ])
$icons : sprite-map ("icons/*. png" );
.next  {
  background: sprite($icons , arrow) no -repeat;
}
.add-button {
  background: sprite($icons , box-add) no -repeat;
}
$icons : sprite-map ("icons/*. png" );
.sprite-base { background: $icons  no -repeat; }
.next  {
  @extend  .sprite-base;
  background-position: sprite-position($icons , arrow);
}
.add-button {
  @extend  .sprite-base;
  @include  sprite-background-position($icons , box-add);
}
  
// 自动添加 width height
$icons : sprite-map ("icons/*. png" );
.sprite-base { background: $icons  no -repeat; }
.next  {
  @extend  .sprite-base;
  @include  sprite-background-position($icons , arrow);
  @include  sprite-dimensions($icons , arrow);
}
 
production 
1
2
3
4
5
6
7
8
9
10
11
12
 # 配置文件中 
# Increment the deploy_version before every 
# release to force cache busting. 
asset_cache_buster do  |http_path, real_path|
"v=1" 
end
asset_cache_buster :none
relative_assets = true 
 
We encourage you to investigate using a rapid
prototyping framework like Serve (http://get-serve.com/ )
or Middleman (http://middlemanapp.com/ ), which include
support for Sass and Compass out of the box.
deploy 
compass compile --force -e production 
1
2
3
4
5
6
7
8
9
10
 if  environment == :production
  output_style = :compact
  end  
http_path = '/my-app' 
relative_assets = false 
images_dir = 'images'  
http_images_dir = 'imgs'  
 
添加版权信息
1
2
3
4
5
6
 $copyright -year : unquote("2012" );
$company -name : unquote("Example, Inc." );
 
1
2
 compass compile my_sass_dir/application.scss 
sass --compass my_sass_dir/application.scss  my_css_dir/application.css 
 
 
1
2
3
4
5
6
7
8
9
10
11
 
if  ENV ['STAGING' ]
  relative_urls = true 
  output_style = :compact 
elsif  environment == :production 
  relative_urls = false 
  output_style = :compact 
else  
  relative_urls = true 
  output_style = :expanded 
end 
 
 
1
2
3
4
5
6
7
8
9
10
11
 // compass compile 
eval(File.read ("#{File.dirname(__FILE__)}/config.rb" ))
relative_urls = true 
output_style = :compact
on_stylesheet_save do  |filename|
  
  
  
  `gzip -f 
end  
 
 
网络优化 
PNG is a complex format that can handle a range of image types. Be sure to remove
the alpha layer unless you need transparency. We highly recommend that you install
the free tool Pngcrush and run it on all your PNG images.
http://pmt.sourceforge.net/pngcrush/ 
Beyond the benefits of parallelization, it’s also important to set up your assets hosts
to use a cookieless domain—a domain that doesn’t share cookies with your site. This will
result in fewer bytes being sent to your web server with each image request.
1
2
3
4
 asset_host do  |asset|
  host_number = (asset.hash % 4 ) + 1 
  "http://img-#{host_number} .example.com" 
end 
 
 
1
2
 background-image : inline -url ("logo.gif" );
* background-image : image-url ("logo.gif" );
 
 
1
2
 gem install  css_parser
compass stats
 
 
Scripting 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
$grid -cells: 20 ;
$cell -width: 25 px;
#main {
  $main -width: $grid -cells * $cell -width;
  $main -padding: 10 px;
  width: $main -width;
  padding: $main -padding;
  .siderbar {width: ($main -width - $main -padding*2 )/4 }
}
$pixels -per-em: 16 px/1 em;
5 em * $pixels -per-em 
1 px/2 px => 1 px/2 px; 
$var : 1 px; $var /2 px => 0.5 px
(1 px/2 px) => 0.5 px
1  + (1 px/2 px) => 1.5 px
abs ($number );
ceil ($number );
comparable(13 in , 4 cm);
floor ($number );
percentage(0.4 ); 
round($number ); 
unit ($number );
unitless($number );
alpha($color );
opacity($color );
lightness($color );
red($color );
greyscale($color );
invert($color );
miix($color -1 , $color -2 , [$weight ]);
scale ($color , $lightness : 30 %) ;
nth(foo bar baz, 2 ); 
join($list1 , $list2 , [$separator ]);
length(1  2  3 );
type-of($value );  
if ($condition , $if -true, $if -false)
@function  grid -width($cells ) {
  @return  ($cell -width + $cell -padding) * $cells ;
}
@mixin  thing($class , $prop ) {
  .thing.#{$class } {
  prop-{$prop }: val;
  }
}
@mixin  bang-hack($property , $value , $ie6 -value) {
  #{$property }: $value  !important;
  #{$property }: $ie6 -value;
}
content: "This element is #{$color}" ;
width: calc(10 % + #{$padding });
filter : progid:DXImageTransform.Microsoft.Alpha(
  Opacity=#{$opacity  * 100 }
);
 
 
控制指令 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 @for  $i  from 1  through 5  {
  .rating-#{$i } {
    background-image ; url(/images/rating-#{$i }.png);
  }
}
@for  $i  from 0  through 10  {
  $i : 10  - $i ;
}
@for  $i  from 0  through 10  {
  $i : $i  * 2 ;
}
@each  $section  in  home, about , archive, project {
  nav .#{section} {
    background-image : url(/images/nav/#{$section }.png);
  }
}
@if  $alpha  < 0.2  {
  background-color : black;
} @else  if  $alpha  < 0.5  {
  background-color : gray;
} @else  {
  background-color : white;
}
 
CSS3 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 @import  "compass/css3" ; 
.rounded  {
  @include  border-radius (5 px); 
  @include  box-shadow (#ccc  5px  5px  2px ); 
}
.rounded-one  {
  @include  border-corner-radius (top, left , 5px ); 
}
.pattern  {
  @include  background (
  linear-gradient (
    360deg ,
    #bfbfbf  0 %,
    #bfbfbf  12.5 %,
    #bfbf00  12.5 %,
    #bfbf00  25 %,
    #00bfbf  25 %,
    #00bfbf  37.5 %,
    #bfbf00  37.5 %,
    #00bf00  37.5 %,
    #00bf00  50 %,
    #bf00bf  50 %,
    #bf00bf  62.5 %,
    #bf0000  62.5 %,
    #bf0000  75 %,
    #0000bf  75 %,
    #0000bf  87.5 %,
    #000  87.5 %,
    #000  100 %)); 
  height : 300 px; 
  margin : 100 px auto; 
  width : 400 px; 
}
@mixin  nb-gradient ($bg) { 
  
  $top :scale-color($bg, $lightness: 40 %); 
  $middle -1: scale-color($bg, $lightness: 10 %); 
  $middle -2: scale-color($bg, $lightness: -5 %); 
  $bottom : scale-color($bg, $lightness: -20 %); 
  @include  background-image (linear-gradient(
                              $top, $middle-1  50 %, $middle-2  50 %, $bottom) ); 
}
                              
div :nth-child (2) {
  background : green; 
  
  @include  rotateX (45 deg); 
  @include  translate (0 , 30px ); 
  @include  transform-origin (left, right ); 
  
  @include  box-sizing (border-box); 
  @include  transition (all 1s ); 
  &:hover  {
    @include  border-corner-radius (top, left , 10px ); 
    @include  scale (1 , 2 ); 
  }
}
@include  animation (sport 1s  ease-out  0  infinite  alternate ); 
@include  keyframes (sport){ 
  0% {
    opacity : 0 ; 
  }
  100% {
    opacity : 1 ; 
  }
}
 
960 grid 
1
2
3
 gem install compass-960 -plugin
compass create  -r ninesixty twelve_col 
require  'ninesixty' 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 <section  class ="wrapper container_24" > 
 <header  class ="main grid_24" > 
   Header
  </header > 
  <section  class ="content grid_20" > 
    Content
  </section > 
  <aside  id ="sidebar grid_4" > 
    The last column
  </aside > 
  <footer  class ="main grid_24" > 
    Footer
  </footer > 
</section > 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 $ninesixty -columns: 24 ;
.wrapper {
  @include  grid -container ;
  header.main, footer.main {
    @include  grid (24 );
  }
  #sidebar {
    @include  grid (4 );
  }
  .content {
    @include  grid (20 );
  }
}
.container_24 {
  @include  grid -system (24 );
}
 
vertical rhythm 
(baseline unit/ font-size) = line height
(24px / 36px) = .6666667 em
1
2
3
4
5
6
 h1  {font-size : 48 px  ; line-height : 1.5 em  }
h2  {font-size : 36 px  ; line-height : .666667 em  }
h3  {font-size : 24 px  ; line-height : 1 em  }
h4  {font-size : 20 px  ; line-height : 1.2 em  }
h5  {font-size : 18 px  ; line-height : 1.33333 em  }
p  {margin : 1.5 em 0   }
 
compass 实现
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 @import  "compass/typography" ;
$base -font -size : 16 px;
$base -line -height : 24 px;
@include establish-baseline ;
body {
  font-family : 'Helvetica Neue' , sans-serif ;
  @include debug-vertical -alignment ("../images/debug.png" );
}
h1 {@include adjust-font -size -to (48 px)}
h2 {@include adjust-font -size -to (36 px)}
h3 {@include adjust-font -size -to (24 px)}
h4 {@include adjust-font -size -to (20 px)}
h5 {@include adjust-font -size -to (18 px)}
p {margin: 1.5 em 0 ;}
 
 
$ninesixty-columns (default: 12) controls the default number of grid columns 
$ninesixty-grid-width (default: 960px) controls the default overall grid width 
$ninesixty-gutter-width (default: 20px) controls the default gutter width 
$ninesixty-class-separator (default: '_') sets the word separator for classnames generated by +grid-system 
 
1
2
 p {@include  leader;  @include  trailer; }
h2.important {@include  leader(2);  @include  trailer(2)} 
 
 
The leader mixin adds one baseline unit of margin before
the element, whereas the trailer adds one baseline unit
of margin after the element.
Compass also provides padding-leader and
padding-trailer variants of these mixins
Tips 
compass create bootstrap -r bootstrap-sass --using bootstrap