sass学习笔记--摘录

//$a: Helvetica, sans-serif
//$b: #333
//
//body
//font: 100% $a
//color: $b
//$a: red
//body
//color: $a
$a : red
.box
  color :   $a
 
color前的空格必须,red和$a前的空格必须
 
能够用koala快速执行编译输出
 
嵌套输出方式 nested

一、嵌套输出方式 nestedjavascript

Sass 提供了一种嵌套显示 CSS 文件的方式。例如css

nav {
  ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  li { display: inline-block; }

  a {
    display: block;
    padding: 6px 12px;
    text-decoration: none;
  }
}

在编译的时候带上参数“ --style nested”:html

sass --watch test.scss:test.css --style nested

编译出来的 CSS 样式风格:前端

nav ul {
  margin: 0;
  padding: 0;
  list-style: none; }
nav li {
  display: inline-block; }
nav a {
  display: block;
  padding: 6px 12px;
  text-decoration: none; }

以下图所示:java


 
 
 
 
先安装ruby默认c盘。而后add path 勾选--接着gem install sass 安装sass或者使用淘宝ruby gems镜像安装sass
 
gem soureces -r https://rubygems.org/
 
gem soureces -a https://ruby.taobao.org/
 
gem sources -l
 
gem list 查看安装列表-----------------
 
gem sources 查看安装源
 
 
compass 安装
 
 
gem sources -a https://gems.ruby-china.org  安装会报错  协议错误什么的:解决方法:

关于 Windows 下证书没法验证问题 (certificate verify failed)

ruby 没有包含 SSL 证书,因此 https 的连接被服务器拒绝。npm

解决方法很简单,首先在这里下载证书 http://curl.haxx.se/ca/cacert.pem, 而后再环境变量里设置 SSL_CERT_FILE 这个环境变量,并指向 cacert.pem 文件。gulp

set SSL_CERT_FILE=C:\path\to\cacert.pem
 若是不会协议证书之类的话能够: gem sources -a  http://gems.ruby-china.org
 
 

compass create sassDemo  建立sass环境
 
compass clean删除环境部份内容
 
compass compile 新建
 
require 'compass/import-once/activate'
# Require any additional compass plugins here.
 
# Set this to the root of your project when deployed:
http_path = "/"     
 # 服务器路径
css_dir = "stylesheets"
# css路径
sass_dir = "sass"
# sass路径
images_dir = "images"
# 图片路径
javascripts_dir = "javascripts"
# js路径
 
compass watch  同步监测
 
npm install --global gulp  安装gulp
 
 

1. 全局安装 gulp:

$ npm install --global gulp

2. 做为项目的开发依赖(devDependencies)安装:

$ npm install --save-dev gulp

3. 在项目根目录下建立一个名为 gulpfile.js 的文件:

var gulp = require('gulp');

gulp.task('default', function() {
  // 将你的默认的任务代码放在这
});

4. 运行 gulp:

$ gulp

安装Sass和Compass

sass基于Ruby语言开发而成,所以安装sass前须要安装Ruby。(注:mac下自带Ruby无需在安装Ruby!)sass

window下安装SASS首先须要安装Ruby,先从官网下载Ruby并安装。安装过程当中请注意勾选Add Ruby executables to your PATH添加到系统环境变量。以下图:ruby

安装完成后需测试安装有没有成功,运行CMD输入如下命令:服务器

ruby -v
//如安装成功会打印ruby 2.2.2p95 (2015-04-13 revision 50295) [i386-mingw32]

如上已经安装成功。但由于国内网络的问题致使gem源间歇性中断所以咱们须要更换gem源。(使用淘宝的gem源https://ruby.taobao.org/)以下:

//1.删除原gem源
gem sources --remove https://rubygems.org/

//2.添加国内淘宝源
gem sources -a https://ruby.taobao.org/

//3.打印是否替换成功
gem sources -l

//4.更换成功后打印以下
*** CURRENT SOURCES ***
https://ruby.taobao.org/

Ruby自带一个叫作RubyGems的系统,用来安装基于Ruby的软件。咱们可使用这个系统来 轻松地安装SassCompass。要安装最新版本的SassCompass,你须要输入下面的命令:

//安装以下(如mac安装遇到权限问题需加 sudo gem install sass)gem install sass
gem install compass

在每个安装过程当中,你都会看到以下输出:

Fetching: sass-3.x.x.gem (100%)
Successfully installed sass-3.x.x
Parsing documentation for sass-3.x.x
Installing ri documentation for sass-3.x.x
Done installing documentation for sass after 6 secon
1 gem installed

安装完成以后,你应该经过运行下面的命令来确认应用已经正确地安装到了电脑中:

sass -v
Sass 3.x.x (Selective Steve)

compass -v
Compass 1.x.x (Polaris)
Copyright (c) 2008-2015 Chris Eppstein
Released under the MIT License.
Compass is charityware.
Please make a tax deductable donation for a worthy cause: http://umdf.org/compass

以下sass经常使用更新、查看版本、sass命令帮助等命令:

//更新sassgem update sass

//查看sass版本sass -v

//查看sass帮助sass -h

编译SASS

sass编译有不少种方式,如命令行编译模式、sublime插件 SASS-Build、编译软件 koala、前端自动化软件 codekit、Grunt打造前端自动化工做流 grunt-sass、Gulp打造前端自动化工做流 gulp-ruby-sass等。

2. 命令行编译;

//单文件转换命令sass input.scss output.css

//单文件监听命令sass --watch input.scss:output.css

//若是你有不少的sass文件的目录,你也能够告诉sass监听整个目录:sass --watch app/sass:public/stylesheets

2-1. 命令行编译配置选项;

命令行编译sass有配置选项,如编译事后css排版、生成调试map、开启debug信息等,可经过使用命令sass -v查看详细。咱们通常经常使用两种--style--sourcemap

//编译格式sass --watch input.scss:output.css --style compact

//编译添加调试mapsass --watch input.scss:output.css --sourcemap

//选择编译格式并添加调试mapsass --watch input.scss:output.css --style expanded --sourcemap

//开启debug信息sass --watch input.scss:output.css --debug-info
  • --style表示解析后的css是什么排版格式;
    sass内置有四种编译格式:nestedexpandedcompactcompressed
  • --sourcemap表示开启sourcemap调试。开启sourcemap调试后,会生成一个后缀名为.css.map文件。

2-2. 四种编译排版演示;

//未编译样式.box {
  width: 300px;
  height: 400px;
  &-title {
    height: 30px;
    line-height: 30px;
  }
}

# nested 编译排版格式

/*命令行内容*/sass style.scss:style.css --style nested

/*编译事后样式*/.box {
  width: 300px;
  height: 400px; }
  .box-title {
    height: 30px;
    line-height: 30px; }

# expanded 编译排版格式

/*命令行内容*/sass style.scss:style.css --style expanded

/*编译事后样式*/.box {
  width: 300px;
  height: 400px;
}.box-title {
  height: 30px;
  line-height: 30px;
}

# compact 编译排版格式

/*命令行内容*/sass style.scss:style.css --style compact

/*编译事后样式*/.box { width: 300px; height: 400px; }.box-title { height: 30px; line-height: 30px; }

# compressed 编译排版格式

/*命令行内容*/sass style.scss:style.css --style compressed

/*编译事后样式*/.box{width:300px;height:400px}.box-title{height:30px;line-height:30px}

3. 软件方式编译;

这里推荐koala&codekit,它们是优秀的编译器,界面清晰简洁,操做起来也很是简单。鉴于koala是免费编译器,简单操做以下图:

相关文章
相关标签/搜索