sass安装 使用
因为sass依赖于ruby环境,所以装sass之前先确认装了ruby。先导官网下载个ruby
在安装的时候,请勾选Add Ruby executables to your PATH这个选项,添加环境变量,不然以后使用编译软件的时候会提示找不到ruby环境

然后直接在命令行中输入
gem install sass
按回车键确认,等待一段时间就会提示你sass安装成功。最近因为墙的比较厉害,如果你没有安装成功,那么请参考下面的淘宝的RubyGems镜像安装sass,如果成功则忽略。
如果要安装beta版本的,可以在命令行中输入
gem install sass --pre
你还可以从sass的Git repository来安装,git的命令行为
git clone git://github.com/nex3/sass.git
cd sass
rake install
升级sass版本的命令行为
gem update sass
查看sass版本的命令行为
sass -v
你也可以运行帮助命令行来查看你需要的命令
sass -h
gem sources命令来配置源,先移除默认的https://rubygems.org源,然后添加淘宝的源https://ruby.taobao.org/,然后查看下当前使用的源是哪个,如果是淘宝的,则表示可以输入sass安装命令gem install sass了,关于常用gem source命令可参看:常用的gem source
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org
# 请确保只有 ruby.taobao.org
$ gem install sass
gem sources --remove https://rubygems.org/
gem sources -a http://gems.ruby-china.org/
gem sources -l
sass test.scss
sass --watch test.scss:test.css
sass --watch sassFileDirectory:cssFileDirectory
$blue:#1875e7;
div{color:$blue;}
$left:left;
.rounded {border-#{$left}-radius:5px;}
!default即可。 sass的默认变量一般是用来设置默认值,然后根据需求来覆盖的,覆盖的方式也很简单,只需要在默认变量之前重新声明下变量即可nth($var,$index)取值$px: 5px 6px 8px 10px;//一维数组
$pxT: 10px 20px , 30px 40px;//二维数组
$trpx:(1px solid #eee ) (16px solid #aaa);//二维数组 .class8 {
font-size: nth($px,3);
}
.class9 {
border: nth($trpx,1);
}
.class10 {
margin: nth($pxT,2);
}
$map: (key1: value1, key2: value2, key3: value3);。可通过map-get($map,$key)取值。$headings:(h1:2em,h2:1.5em,h3:1em);
.class11 {
font-size: map-get($headings,h2);
} @each $heade , $size in $headings {
#{$heade} {
font-size: $size;
}
}
$var:10;
body{margin:(14px/2);top:50px+100px;right:$var*10%;}
div{
color:$blue;
h1 {
color:red;
}
}
p {
border:{
color:red;
}
}
}
a {
&:hover {color:red;}
}
#content aside { color: red;body.ie & { color: green }}
.container { h1, h2, h3 {margin-bottom: .8em} }
nav, aside { a {color: blue} }
require 'sass/supports'这一行,在下面一行添加Encoding.default_external = Encoding.find('utf-8')标准的CSS注释 /* comment */ ,会保留到编译后的文件。
单行注释 // comment,只保留在SASS源文件中,编译后被省略。
在/*后面加一个感叹号,表示这是"重要注释"。即使是压缩模式编译,也会保留这行注释,通常可以用于声明版权信息。
/*!
重要注释!
*/
.class1 {
border: 1px solid #ddd;
}
.calss2 {
@extend .class1;
font-size: 20px;
}

@mixin left {
float: left;
margin-left: 10px;
}
.class3 {
@include left;
}
@mixin right($value:10px) {
float: right;
margin-right: $value;
}
.class5 {
@include right()
}
.class4 {
@include right(40px)
}
@mixin rounded ($vert,$horz,$radius:10px) {
border-#{$vert}-#{$horz}-radius:$radius;
-moz-border-#{$vert}-#{$horz}-radius:$radius;
-webkit-border-#{$vert}-#{$horz}-radius:$radius;
}
.nav {
@include rounded(top,left)
}
.footer {
@include rounded(top,left,5px)
}
多组值参数mixin
$variables...。 @mixin box-shadow ($shadow...) {
-webkit-box-shadow:$shadow;
box-shadow: $shadow;
}
@mixin max-screen ($res) {
@media only screen and (max-width: $res) {
@content;
}
}
@include max-screen(480px) {
body {color:red;}
}
lighten(#cc3, 10%) // #d6d65c
darken(#cc3, 10%) // #a3a329
grayscale(#cc3) // #808080
complement(#cc3) // #33c
.class6 {
@if 1+1 == 2 {color:red}
@if 5 < 3 {color:blue}@else {
background-color: #FFF
}
}
@for $var from <start> through <end>和@for $var from <start> to <end>。$i表示变量,start表示起始值,end表示结束值,这两个的区别是关键字through表示包括end这个数,而to则不包括end这个数。 @for $i from 1 to 10 {
.border-#{$i} {
border: #{$i}px solid red;
}
}
$i:6;
@while $i > 0 {
.item-#{$i} {width:20px;}
$i:$i - 2;
}
@each $member in a,b,c,d {
.#{$member} {
background-image: url("/image/#{$member}.jpg");
}
}
@function double($n) {
@return $n * 2;
}
.class7 {
width: double(5px);
}
//单个选择器跳出
.parent {
color:red;
@at-root .child {
width: 100px;
}
}
//多个选择器跳出
.parent2 {
color:blue;
@at-root {
.child1 {width: 100px;}
.child2 {width: 200px;}
}
}
@at-root只会跳出选择器嵌套,而不能跳出@media或@support,如果要跳出这两种,则需使用@at-root (without: media),@at-root (without: support)//跳出父级元素嵌套
@media print {
.parent2 {
color: red;
@at-root .child3 {
color: blue;
}
}
} //跳出media嵌套 父级有效
@media print4 {
.parent4 {
color: red;
@at-root (without: media) {
.child4 {
width: 200px;
}
}
}
} //跳出media和父级
@media print5 {
.parent5 {
color:red;
@at-root (without:all) {
.child5{height: 200px;}
}
}
}
.child6 {
@at-root .parent6 & {
height: 300px;
}
}
%%。这种选择器的优势在于:如果不调用则不会有任何多余的css文件,避免了以前在一些基础的文件中预定义了很多基础的样式,然后实际应用中不管是否使用了@extend去继承相应的样式,都会解析出来所有的样式。占位选择器以%标识定义,通过@extend调用。 %ir {
color:transparent;
text-shadow:none;
background-color: transparent;
border:0;
}
%clearfix {
@if $ie7 {
*zoom :1;
}
&:before,
&:after {
content: "";
display: table;
font: 0/0;
}
&:after {
clear: both;
}
}
#header {
width: 2100px;
@extend %ir;
}
.ir {
@extend %ir;
}
sass安装 使用的更多相关文章
- sass 安装、配置,css规则
http://blog.csdn.net/oyuemijindu/article/details/51036096 --sass 安装 一安装 1.ruby下载,可以到官网下载 ,注意如果是系统如果 ...
- Sass安装(windows版)
Sass安装(windows版) 在 Windows 平台下安装 Ruby 需要先有 Ruby 安装包,大家可以到 Ruby 的官网(http://rubyinstaller.org/download ...
- win下sass安装失败的一种可能
首先声明,本篇转自CSDN的LZGS_4. 今天我也遇到这个问题,就把文章擅自转载了,方便自己也方便更多的人吧. 因为sass和compass依赖于ruby环境,所以装之前先确认装了ruby.可到官网 ...
- windows下sass安装 以及一些要注意的问题
都说sass 环境难配其时也没那么难 按照以下步骤一下一下来还是挺快的 如果你是喜欢less 那就当我没说 233333 1.sass 是基于ruby这门语言的需要使用 rubygem这个包管理器安装 ...
- SASS安装的那些事
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- sass安装及使用
在Mac系统下,Ruby一般已内置在其中,如果您不能确认是否已安装,或者说你不知道你的Ruby使用的版本,你可以打开你的命令工具: $ ruby -v 安装sass 在大多数情况和大部分人群中,还是喜 ...
- lnmp git ruby sass 安装
1 cd .. 2 ls 3 cd mzx/ 4 ls 5 cd 桌面 6 cd lnmp1.4-full/ //到lnmp 的官网上下载后,根据官网的提示来安装lump 7 ls 8 install ...
- sass学习之一:sass安装compass部署
主要参考 http://www.jianshu.com/p/5bfc9411f58f -------------------------------------------- sass基于ruby 需 ...
- sass安装方法,绝对好用的方式
系统重做了,很多东西都重装,sass也一样,结果在安装的过程中遇到了问题,这里记录下,也给同样遇到问题的朋友们一个思路.本方法是参照http://www.w3cplus.com/sassguide/i ...
随机推荐
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
- CentOS7 续续
1.配置网络,虚拟机为桥接模式,IP地址为 192.168.100+学号/24,配置完成后可以通过ping物理机192.168.100段,或者ping 192.168.100.140验证2.通过临时与 ...
- python os模块(1)
os模块主要处理文件和目录(文件夹)的创建.删除.检查判定.属性值修改.路径修改. (1)获取当前目录的两种方法 1 os.getcwd() os.path.abspath('.') (2)创建文件夹 ...
- Cheatsheet: 2015 11.01 ~ 11.30
Golang Roadomatic: Node vs. Go Quick Guide to Golang for Java Developers 3 Go Gotchas Web Choosing a ...
- Redis的安装与部署
为了解决公司产品数据增长过快,初始化太耗费时间的问题,决定使用redis作为缓存服务器. Windows下的安装与部署: 可以直接参考这个文章,我也是实验了一遍:http://www.runoob.c ...
- 转!!XML,DTD,XSD,XSL的区别
XML=可扩展标记语言(eXtensible Markup Language).可扩展标记语言XML是一种简单的数据存储语言,使用一系列简单的标记描述数据,而这些标记可用 方便的方式建立,虽然XML占 ...
- ubuntu1404服务器版中设置root用户
刚安装完没有设置root用户 sudo passwd root 根据提示输入密码,ok . 关闭服务器: shutdown -h now
- 课时8—弹窗modal
首先弹窗的实现效果如下: 主要实现的代码如下: CSS: .header,.footer,.wrap-page{ position:absolute; left:; right:; backgroun ...
- CSS3中的Transition属性详解
w3c标准中对CSS3的transition这是样描述的:“CSS的transition允许CSS的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击.获得焦点.被点击或对元素任何改变中触发, ...
- Node.js 快速了解
最近在学习目前非常火的Node.js 写了一份精简易懂的笔记用于快速了解Node.js技术.如有不对的地方还请多多指教. 注:此篇博文不断更新中. 第一部分:快速了解 1.Node.js是什么? No ...