sass安装和语法
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的常用语法,我写在注释里了。
丑丑页面预览:

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安装和语法的更多相关文章
- sass安装 使用
一 什么是sass sass是一种css开发工具.提供了很多便利的写法,使得css开发变得简单 易维护 sass有两种后缀名文件:一种后缀名为sass,不使用大括号和分号:另一 ...
- SASS安装的那些事
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- 【css预处理器】------sass的基本语法------【巷子】
001.安装sass 1.删除gem源:gem sources --remove https://rubygems.org/ 2.添加国内源:gem sources -a http://gems.ru ...
- Sass 安装到使用
sass学习 Sass 可以通过以下三种方式使用:作为命令行工具:作为独立的 Ruby 模块 (Ruby module):或者作为 Rack-enabled 框架的插件(例如 Ruby on Rail ...
- 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安装及使用
在Mac系统下,Ruby一般已内置在其中,如果您不能确认是否已安装,或者说你不知道你的Ruby使用的版本,你可以打开你的命令工具: $ ruby -v 安装sass 在大多数情况和大部分人群中,还是喜 ...
随机推荐
- Python学习笔记【第八篇】:Python内置模块
什么时模块 Python中的模块其实就是XXX.py 文件 模块分类 Python内置模块(标准库) 自定义模块 第三方模块 使用方法 import 模块名 form 模块名 import 方法名 说 ...
- hbase概念解析
hbase是一种nosql数据库.是一个高可靠,高性能,面向列,可伸缩,实时读取的分布式数据库. hbase一般由行键,时间戳,列族,列,表格单元,行组成. 行一般由一个行键和一个或多个具有关联关系值 ...
- mongo 更新字段值,若不存在则自动创建
查询语句 db.getCollection("A表").update( { "id":{$eq:11} } ,{ $set:{"a" ...
- 将本地代码上传到github走过的坑
1.因为github是服务端,需要自己在自己的电脑上安装一个客户端git 2.配置SSH(配置一次就好了) github是不能随便上传代码上去的,而是通过一种网络协议---SSH授权的.SSH是一种网 ...
- odoo开发笔记--开启后台日志记录
odoo后台日志记录功能 修改启动文件odoo.conf 将参数logfile注释放开, logfile = /var/log/odoo/odoo-server.log login_message = ...
- Redis(2)---数据持久化
数据持久化 Redis有两种持久化的方式:快照(RDB文件)和追加式文件(AOF文件) (1)RDB持久化方式是在一个特定的间隔保存某个时间点的一个数据快照.(默认模式) (2)以日志的形式来记录每个 ...
- Android--Menus
前言 本篇博客讲解一下菜单Menu的使用.菜单在windows应用中使用十分广泛,几乎所有的windows应用都有菜单,Android中也加入了菜单的支持.从官方文档了解到,从Android3.0(A ...
- HttpContextAccessor不会出现线程同步问题?
我有一段比较常规的.net core mvc代码,就是StartUp函数中注册HttpContextAccessor到系统DI工厂中,如图: 然后调用方是service层,这个service层是使用a ...
- 剑指offer例题分享--7
前言:继续前面的分享... 面试题31: 代码如下: #include<iostream> #include<limits.h> using namespace std; bo ...
- 从零开始学 Web 之 Vue.js(四)Vue的Ajax请求和跨域
大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...