sass安装和语法

时间:2023-02-21 17:50:54

1.简介

sass 它的基本思想是,用一种专门的编程语言,进行网页样式设计,然后再编译成正常的CSS文件。这被叫做“css预处理器”(css preprocessor)。它提供了很便利的语法,节省了我们写css的时间。

2.安装

  (1)首先确保你的电脑安装了 ruby (传送门 https://www.ruby-lang.org/zh_cn/downloads/)

// 控制台查看是否安装成功
ruby -v

 

 (2)安装 sass

gem install sass

3.使用

  (1)用编辑器 新建文件夹 demo ,在demo里新建文件 demo.scss ,代码如下

.list_1 {
ul {padding-left: 1.6rem;}
li {
border-bottom: 1px solid #ddd;padding-right: 1.6rem;
a {
display: block;height: 4rem;line-height: 4rem;overflow: hidden;font-size: 1.4rem;
background:url("../image/icon_goto.png") right center no-repeat;
background-size: auto 1.4rem;
padding-right: 1.5rem;
}
time {float: right;color: #999;}
}
}

  (2)控制台 进入demo文件夹下

// demo.css 是生成后的css文件名
sass demo.scss demo.css

  

4.sass提供的四种编译风格

// nested:嵌套缩进的css代码,它是默认值。
// expanded:没有缩进的、扩展的css代码。
// compact:简洁格式的css代码。
// compressed:压缩后的css代码。

  比如

sass --style compressed test.sass test.css

  

  

5.sass 语法

   我觉得sass的格式和jade书写格式很像,结合sass的语法写了个demo,希望能帮助大家。

  注意 : 这里的是在控制台下直接用sass编译下的语法(不需要{}和;等),但是如果你需要在grunt下使用,请参考 http://www.w3cplus.com/sassguide/syntax.html

  页面结构很简单,这里主要讲scss的常用语法,我写在注释里了。

  丑丑页面预览:

sass安装和语法

  index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="index.css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<div class="lay01">
<a href="#">cynthia</a>
<label for="">something</label> <br>
<br> <div class="lay01-1">
<h1>hello sass</h1>
</div>
</div>
</body>
</html>

  css.scss

*
padding: 0
margin: 0
border: 0
outline: 0
font-size: 12px body
background: #f4f4f4 a
text-decoration: none
&:hover
cursor: pointer // each循环
$headings: (h1:2em,h2:1.5em,h3:1.2em)
@each $header,$size in $headings
#{$header}
font-size: $size // for循环
@for $i from 1 through 3
.item-#{$i}
width: 2em * $i // 多个字段的数据循环
$animal-data: (puma,black,default),(sea-sulg,blue,pointer),(egret,white,move)
@each $animal,$color,$cursor in $animal-data
.#{$animal}-icon
background: url(img/#{$animal}.png)
border: 1px #ddd solid
cursor: $cursor

  css.scss生成的css.css

* {
padding: 0;
margin: 0;
border: 0;
outline: 0;
font-size: 12px; } body {
background: #f4f4f4; } a {
text-decoration: none; }
a:hover {
cursor: pointer; } h1 {
font-size: 2em; } h2 {
font-size: 1.5em; } h3 {
font-size: 1.2em; } .item-1 {
width: 2em; } .item-2 {
width: 4em; } .item-3 {
width: 6em; } .puma-icon {
background: url(img/puma.png);
border: 1px #ddd solid;
cursor: default; } .sea-sulg-icon {
background: url(img/sea-sulg.png);
border: 1px #ddd solid;
cursor: pointer; } .egret-icon {
background: url(img/egret.png);
border: 1px #ddd solid;
cursor: move; } /*# sourceMappingURL=css.css.map */

  index.scss

// 引入外部css文件
@import "css.css" // 变量
$blue:#1875e7 // 代码块
@mixin font1
font-family: 'Microsoft Yahei'
color: #ddd // 嵌套
.lay01
background: $blue
border: 1px #ddd solid
a
@include font1
// 计算
font-size: 16px - 1px
label
background: red
font-size: 12px
display: block
width: 100px
height: 30px
line-height: 30px
text-align: center
.lay01-1
width: 100px
height: 100px
background: yellow
h1
font-size: 20px
color: green

  index.scss生成的index.css

@import url(css.css);
.lay01 {
background: #1875e7;
border: 1px #ddd solid; }
.lay01 a {
font-family: "Microsoft Yahei";
color: #ddd;
font-size: 15px; }
.lay01 label {
background: red;
font-size: 12px;
display: block;
width: 100px;
height: 30px;
line-height: 30px;
text-align: center; }
.lay01 .lay01-1 {
width: 100px;
height: 100px;
background: yellow; }
.lay01 .lay01-1 h1 {
font-size: 20px;
color: green; } /*# sourceMappingURL=index.css.map */
 

sass安装和语法的更多相关文章

  1. sass安装 使用

    一 什么是sass      sass是一种css开发工具.提供了很多便利的写法,使得css开发变得简单  易维护       sass有两种后缀名文件:一种后缀名为sass,不使用大括号和分号:另一 ...

  2. SASS安装的那些事

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  3. 【css预处理器】------sass的基本语法------【巷子】

    001.安装sass 1.删除gem源:gem sources --remove https://rubygems.org/ 2.添加国内源:gem sources -a http://gems.ru ...

  4. Sass 安装到使用

    sass学习 Sass 可以通过以下三种方式使用:作为命令行工具:作为独立的 Ruby 模块 (Ruby module):或者作为 Rack-enabled 框架的插件(例如 Ruby on Rail ...

  5. sass 安装、配置,css规则

    http://blog.csdn.net/oyuemijindu/article/details/51036096 --sass 安装 一安装  1.ruby下载,可以到官网下载 ,注意如果是系统如果 ...

  6. Sass安装(windows版)

    Sass安装(windows版) 在 Windows 平台下安装 Ruby 需要先有 Ruby 安装包,大家可以到 Ruby 的官网(http://rubyinstaller.org/download ...

  7. win下sass安装失败的一种可能

    首先声明,本篇转自CSDN的LZGS_4. 今天我也遇到这个问题,就把文章擅自转载了,方便自己也方便更多的人吧. 因为sass和compass依赖于ruby环境,所以装之前先确认装了ruby.可到官网 ...

  8. windows下sass安装 以及一些要注意的问题

    都说sass 环境难配其时也没那么难 按照以下步骤一下一下来还是挺快的 如果你是喜欢less 那就当我没说 233333 1.sass 是基于ruby这门语言的需要使用 rubygem这个包管理器安装 ...

  9. sass安装及使用

    在Mac系统下,Ruby一般已内置在其中,如果您不能确认是否已安装,或者说你不知道你的Ruby使用的版本,你可以打开你的命令工具: $ ruby -v 安装sass 在大多数情况和大部分人群中,还是喜 ...

随机推荐

  1. Node&period;js高效按行输出文件内容

    const fs = require('fs'); const EventEmitter = require('events'); const util = require('util'); cons ...

  2. 关于adb连接手机offline的问题解决

    win7-64位系统.对于windows系统,adb devices 显示offline一般可能有两个原因: 1 )端口被占用. 解决方式是:查找端口号,结束占用进程: adb nodaemon se ...

  3. HDU 5901 Count primes &lpar;1e11内的素数个数&rpar; -2016 ICPC沈阳赛区网络赛

    题目链接 题意:求[1,n]有多少个素数,1<=n<=10^11.时限为6000ms. 官方题解:一个模板题, 具体方法参考wiki或者Four Divisors. 题解:给出两种代码. ...

  4. 微信支付官方SDK V3 &period;NET版的坑

    但是支付成功后却不能正确的执行支付结果js回调函数.看看其页面的点击事件是放在asp:Button上面的.我们知道在asp.net webform中,按钮的点击是有页面回调后台的.也就是其实点击了之后 ...

  5. RAC日常管理

    RAC日常管理 OEM RAC守护进程 ls -l /etc/init.d/init.* Init.crs init.srsd init.cssd init.evmd RAC日常管理命令 - $ORA ...

  6. 嵌入式C快速翻转一个任何类型的数的二进制位

    unsigned char reverse_bits(unsigned char value) { unsigned char answer , i ; answer = 0 ; for(i = 1 ...

  7. Sqlserver事务隔离级别详解

    sqlserver存储方式   页    sqlserver是以页的形式存储数据,每个数据页的大小为8KB,sqlserver会把空间分为多个页,sqlserver与数据交互单位最小的io操作就是页级 ...

  8. SpringBoot&plus; Mybatis 搭建

    spring boot+mybatis整合   LZ今天自己搭建了下Spring boot+Mybatis,比原来的Spring+SpringMVC+Mybatis简单好多.其实只用Spring bo ...

  9. Mysql 和 Postgresql&lpar;PGSQL&rpar; 对比

    Mysql 和 Postgresql(PGSQL) 对比 转载自:http://www.oschina.net/question/96003_13994 PostgreSQL与MySQL比较 MySQ ...

  10. U3D的控制

    做游戏少不了控制,但是一个成熟的游戏引擎,是不能简单仅仅获取键盘中或者遥感确定的按键来控制,要考虑到用户更改游戏按键的情况,当然也得考虑到不同设备的不通输入方式,比如U3D是可以运行在iphone上的 ...