本文仅适用于Windows系统。css
1、安装Rubyhtml
Sass是用Ruby语言写的,可是二者的语法没有关系,因此学 Sass 不用学 Ruby,只是必须先安装Ruby,而后再安装Sass。sass
Linux和Mac已自带Ruby,不用再安装。Windows用户能够从这里下载Ruby的安装程序。ruby
我下载的是第二个,Ruby 2.3.1 (x64)post
安装过程没什么麻烦的地方,按提示来就能够。url
2、安装SASSspa
进入运行cmd进入命令提示符,输入ruby -v查看版本号,若是能正确显示版本号,则说明ruby安装成功。debug
而后输入gem install sass进行安装。code
可能会出现下图(提示Could not find a valid gem 'sass')的状况,能够参考这篇文章解决。htm
正常状况下显示的结果是这样的:
3、使用SASS
要编译的scss文件(mystyle.scss)以下:
$anime-time: 8s; $box-size: 350px; $clip-distance: .05; $clip-size: $box-size * (1 + $clip-distance * 2); $path-width: 2px; $main-color: #5FB9D5; $codepen-logo-path: url('//blog.codepen.io/wp-content/uploads/2012/06/Button-White-Large.png'); %full-fill { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .bb { @extend %full-fill; width: $box-size; height: $box-size; margin: auto; background: $codepen-logo-path no-repeat 50% / 70% rgba(#000, .1); color: $main-color; box-shadow: inset 0 0 0 1px rgba($main-color, .5); &::before, &::after { @extend %full-fill; content: ''; z-index: -1; margin: -1 * $clip-distance * 100%; box-shadow: inset 0 0 0 $path-width; animation: clipMe $anime-time linear infinite; } &::before { animation-delay: $anime-time * -.5; } // for debug &:hover { &::after, &::before { background-color: rgba(#f00, .3); } } } @keyframes clipMe { 0%, 100% {clip: rect(0px, $clip-size, $path-width, 0px); } 25% {clip: rect(0px, $path-width, $clip-size, 0px); } 50% {clip: rect($clip-size - $path-width, $clip-size, $clip-size, 0px); } 75% {clip: rect(0px, $clip-size, $clip-size, $clip-size - $path-width); } } ///// html, body { height: 100%; } body { position: relative; background-color: #0f222b; } *, *::before, *::after { box-sizing: border-box; }
进入须要编译的scss所在的目录,执行sass style.scss style.css
以后可在该目录得到编译后的css文件以及css.map文件。
scss文件至关于源文件,css至关于编译后的文件,当检查到页面问题的时候,看到的是css,可是须要修改的是scss文件,这个css.map就是两个文件的对应关系表。
参考资料:
http://www.sass-zh.com/
http://www.haorooms.com/post/sass_css