本文主要讲解Compass的内容,众所周知Compass是Sass的工具库,如果对Sass不甚了解的同学可以移步 邂逅Sass和Compass之Sass篇 Sass本身只是一个“CSS预处理器”,Compass在它的基础上,封装了一系列的模块和模板,补充了Sass的功能。

1.Compass的安装

和Sass一样,Compass也是用Ruby语言开发的,所以在安装Sass之前必须先安装Ruby,安装Ruby的过程就不再赘述,安装好Ruby后可以直接在命令行输入下面的命令

sudo gem install compass

windows在cmd中输入,但是需要省略前面的sudo。

正常情况下,Compass(连同Sass)就安装好了。

2.Compass初始化一个项目

接下来,要创建一个属于我们自己的Compass项目,假定它的名字叫做learn-compass-init,那么在命令行输入

compass create learn-compass-init

在当前的目录下就会生成一个learn-compass-init子目录(提示:windows玩家可以在需要创建的文件中按住shift+鼠标右键选择在此处打开命令行窗口)。

进入刚刚创建的子目录

cd learn-compass-init

你会看到如下结构,其中config.rb文件,是项目的配置文件。还有两个子目录sass和stylesheets,前者存放我们需要编写的Sass源文件,后者存放编译后的css文件

3.Compass编译一个项目

了解Sass的都知道,我们编写的后缀名为scss的文件只有编译成css文件,才能用在我们的网站上,所以Compass提供了一系列的编译命令。 在项目的根目录运行如下命令

compass compile

会将Sass子目录中的后缀名scss文件编译成css文件,并保存在stylesheets子目录中。

有人会说修改一次scss文件就需要执行一遍compass compile太过麻烦,所以compass还提供了自动编译命令如下

compass watch

运行该命令后,只要scss文件发生修改,就会自动编译成stylesheets子目录中对应css文件。

默认状态下,编译出来的css文件会带有大量的注释,但是我们的只需要压缩后的css文件,这时就需要使用如下命令

compass compile --output-style compressed

4.Compass中的模块

Comapss采用模块结构,不同的模块提供不同的功能,我们在开发中可以按需来引入模块,下面我将着重讲述一下各个模块的主要功能。

Compass内置了六大模块,其中包括如下

-   reset
- css3
- layout
- typography
- utilities
- helpers

Reset模块:是浏览器的重置模块,减少浏览器的差异性,即重置浏览器间的差异性。

Layout模块:提供了页面布局的控制能力,比如讲一个容器内的子元素横向纵向占满。

值得注意的是,只有Reset模块和Layout模块是需要显式指定引入的,即只要@import "compass" 就可以引入其他模块。

css3模块:提供了跨浏览器的css3的能力,相信你用过以后再也不会因为加浏览器前缀而头疼不已。

Helpers模块:内含一系列的函数,跟Sass中的函数列表很像(用的很少但是功能很强大)。

Typography模块:修饰文本的样式,垂直韵律。

Utilities模块:可以说Compass将没有办法放到其他模块的内容都放在了该模块中。

其实Compass还提供了Browser Support的方法:它主要用于配置Compass默认支持哪些浏览器,对于指定的浏览器默认支持到哪一个版本,一旦修改就会影响其他六个模块的输出,需要针对不同的浏览器做不同的适配。

关于各个模块使用办法以及特色我将会下面的文章中一一讲述。

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}
/*
h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}
*/
body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/
/*
table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}*/
.postBody a:link, .postBody a:visited, .postBody a:active ,.postBody a,.postBody a:hover,{
text-decoration: none;
}
a:hover{
cursor: pointer;
}
/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

最新文章

  1. log4j分离日志输出 自定义过滤 自定义日志文件
  2. filterHTML
  3. 论文阅读(Xiang Bai——【TIP2014】A Unified Framework for Multi-Oriented Text Detection and Recognition)
  4. U-boot中的FDT
  5. VMware安装64位操作系统提示Intel VT-x处于禁用状态的解决办法
  6. JSP导出Excel文件
  7. C#发送邮件三种方法(Localhost,SMTP,SSL-SMTP)
  8. 开学&东大一周游记
  9. 【G】开源的分布式部署解决方案(三) - 一期规划定稿与初步剖析
  10. 3299: [USACO2011 Open]Corn Maze玉米迷宫
  11. Assembly Experiment5
  12. Linux OS7 常用
  13. 如何用impress.js写有逼格的ppt
  14. Matlab 如何输入矩阵
  15. 题解 P2920 【[USACO08NOV]时间管理Time Management】
  16. 1、pyspider安装
  17. 2017-2018 Exp3 MAL_免杀原理与实践 20155214
  18. git 权限问题:insufficient permission for adding an object to repository database .git
  19. NSDate NSTimerZone 时区转换
  20. getField()与getDeclaredField()的区别

热门文章

  1. IT(然而其实是。。hdu5244?)
  2. Caffe框架详细梳理
  3. SpringMVC 之 表单标签
  4. 洛谷P1195 口袋的天空
  5. 「Python」python-nmap安装与入门
  6. synchronized 加锁Integer对象(数据重复)详解
  7. 【整理】explain、type、extra用法和结果的含义
  8. JSOI2008 小店购物
  9. 复制自身程序到windows目录和system32目录下
  10. [译] man 7 pthreads