scss学习笔记
1、引用父选择符: &
#main {
color: black;
a {
font-weight: bold;
&:hover { color: red; }
}
}
2、font:2px/3px 代表 字体大小2px 且 line-height:3px
.funky {
font: 2px/3px {
family: fantasy;
size: 30em;
weight: bold;
}
}
3、Placeholder Selectors: %foo
//如果没有找到%extreme,就不会编译出东西
#context a%extreme {
color: blue;
font-weight: bold;
font-size: 2em;
}
//。notice 或者#notice 都可以接受
.notice {
@extend %extreme;
} // ---------编译为-------
#context a.notice {
color: blue;
font-weight: bold;
font-size: 2em; }
4、Variables: $
$width: 5em; 》》》》》》》》》》》
#main {
width: $width;
} /*
SassScript 支持六种主要的数据类型: 数字(例如 1.2、13、10px)
文本字符串,无论是否有引号(例如 "foo"、'bar'、baz)
颜色(例如 blue、#04a3f9、rgba(255, 0, 0, 0.5))
布尔值(例如 true、false)
空值(例如 null)
值列表,用空格或逗号分隔(例如 1.5em 1em 0 2em、Helvetica, Arial, sans-serif)
*/ 字符串
虽然说可以接受“”或没有引号,但在编译#{}时,就例外,这要注意 @mixin firefox-message($selector) {
body.firefox #{$selector}:before {
content: "Hi, Firefox users!";
}
} @include firefox-message(".header"); 》》》》》》》》》》》》》》
body.firefox .header:before {
content: "Hi, Firefox users!"; } 如果没有给引号,就error,因为.header 是class,而文本都是string,这就是要注意的
5、Interpolation: #{}
$name: foo;
$attr: border;
p.#{$name} {
#{$attr}-color: blue;
} //-------------------------------- p.foo {
border-color: blue; }
p {
$font-size: 12px;
$line-height: 30px;
font: #{$font-size}/#{$line-height};
}
// -----------------------------------
p {
font: 12px/30px; }
6、变量默认值: !default
你可以在变量尚未赋值前,通过在值的末尾处添加 !default 标记来为其指定。 也就是说,如果该变量已经被赋值, 就不会再次赋值, 但是,如果还没有被赋值,就会被指定一个值。
$content: "First content";
$content: "Second content?" !default;
$new_content: "First time reference" !default; #main {
content: $content;
new-content: $new_content;
} //-------------------------------------------------------------
#main {
content: "First content";
new-content: "First time reference"; }
7、 @import 可 引入多个 @import "rounded-corners", "text-shadow";
嵌套 @import
For example, if example.scss contains .example {
color: red;
} then #main {
@import "example";
} --------------------------------------------
#main .example {
color: red;
}
8 、 @media 媒体查询
.sidebar {
width: 300px;
@media screen and (orientation: landscape) {
width: 500px;
}
}
//----------------------------------------------------------
@media screen and (-webkit-min-device-pixel-ratio: 1.5) {
.sidebar {
width: 500px; } }
9、@extend
.error {
border: 1px #f00;
background-color: #fdd;
}
.seriousError {
@extend .error;
border-width: 3px;
}
//-----------------------------------------
.error, .seriousError {
border: 1px #f00;
background-color: #fdd;
}
.seriousError {
border-width: 3px;
}
//------------------------------exp 2------------
.error {
border: 1px #f00;
background-color: #fdd;
}
.error.intrusion {
background-image: url("/image/hacked.png");
}
.seriousError {
@extend .error;
border-width: 3px;
}
//-----------------------------------------------
.error, .seriousError {
border: 1px #f00;
background-color: #fdd; }
.error.intrusion, .seriousError.intrusion {
background-image: url("/image/hacked.png"); }
.seriousError {
border-width: 3px; }
// exp 3
.hoverlink {
@extend a:hover;
}
.comment a.user:hover {
font-weight: bold;
}
// ---------------------------------------------
.comment a.user:hover, .comment .user.hoverlink {
font-weight: bold; }
.error {
border: 1px #f00;
background-color: #fdd;
}
.attention {
font-size: 3em;
background-color: #ff0;
}
.seriousError {
@extend .error;
@extend .attention;
border-width: 3px;
}
10、@if
p {
@if 1 + 1 == 2 { border: 1px solid; }
@if 5 < 3 { border: 2px dotted; }
@if null { border: 3px double; }
}
》》》》
p {
border: 1px solid; }
----
$type: monster;
p {
@if $type == ocean {
color: blue;
} @else if $type == matador {
color: red;
} @else if $type == monster {
color: green;
} @else {
color: black;
}
}
》》》》
p {
color: green; }
11、@for
@for $i from 1 through 3 {
.item-#{$i} { width: 2em * $i; }
}
》》》》
.item-1 {
width: 2em; }
.item-2 {
width: 4em; }
.item-3 {
width: 6em; }
12、@each
@each $animal in puma, sea-slug, egret, salamander {
.#{$animal}-icon {
background-image: url('/images/#{$animal}.png');
}
}
》》》》
.puma-icon {
background-image: url('/images/puma.png'); }
.sea-slug-icon {
background-image: url('/images/sea-slug.png'); }
.egret-icon {
background-image: url('/images/egret.png'); }
.salamander-icon {
background-image: url('/images/salamander.png'); }
13、@while
$i: 6;
@while $i > 0 {
.item-#{$i} { width: 2em * $i; }
$i: $i - 2;
}
》》》》
.item-6 {
width: 12em; } .item-4 {
width: 8em; } .item-2 {
width: 4em; }
14、Mixin Directives
@mixin large-text {
font: {
family: Arial;
size: 20px;
weight: bold;
}
color: #ff0000;
}
.page-title {
@include large-text;
padding: 4px;
margin-top: 10px;
}
》》》》
.page-title {
font-family: Arial;
font-size: 20px;
font-weight: bold;
color: #ff0000;
padding: 4px;
margin-top: 10px; }
@mixin silly-links {
a {
color: blue;
background-color: red;
}
}
@include silly-links;
》》》》
a {
color: blue;
background-color: red; }
15、Arguments
@mixin sexy-border($color, $width) {
border: {
color: $color;
width: $width;
style: dashed;
}
}
p { @include sexy-border(blue, 1in); }
》》》》
p {
border-color: blue;
border-width: 1in;
border-style: dashed; }
@mixin box-shadow($shadows...) {
-moz-box-shadow: $shadows;
-webkit-box-shadow: $shadows;
box-shadow: $shadows;
}
.shadows {
@include box-shadow(0px 4px 5px #666, 2px 6px 10px #999);
}
》》》》
.shadows {
-moz-box-shadow: 0px 4px 5px #666, 2px 6px 10px #999;
-webkit-box-shadow: 0px 4px 5px #666, 2px 6px 10px #999;
box-shadow: 0px 4px 5px #666, 2px 6px 10px #999;
}
@mixin colors($text, $background, $border) {
color: $text;
background-color: $background;
border-color: $border;
}
$values: #ff0000, #00ff00, #0000ff;
.primary {
@include colors($values...);
}
》》》》
.primary {
color: #ff0000;
background-color: #00ff00;
border-color: #0000ff;
}
Passing Content Blocks to a Mixin
@mixin apply-to-ie6-only {
* html {
@content;
}
}
@include apply-to-ie6-only {
#logo {
background-image: url(/logo.gif);
}
}
》》》》
* html #logo {
background-image: url(/logo.gif);
}
$color: white;
@mixin colors($color: blue) {
background-color: $color;
@content;
border-color: $color;
}
.colors {
@include colors { color: $color; }
}
》》》》
.colors {
background-color: blue;
color: white;
border-color: blue;
}
16、Function Directives
$grid-width: 40px;
$gutter-width: 10px; @function grid-width($n) {
@return $n * $grid-width + ($n - 1) * $gutter-width;
} #sidebar { width: grid-width(5); }
//#sidebar { width: grid-width($n: 5); }
>>>>
#sidebar {
width: 240px; }
scss学习笔记的更多相关文章
- scss 学习笔记
由于没有办法在网络上找到适合顾客的模板,同时之前自己写css也没有很好的管理方式,最终选择了scss. Nested #main p { color: #00ff00; width: 97%; .re ...
- SCSS学习笔记(一)
SCSS的由来 SCSS就是加强版的CSS,要讲SCSS那就一定要从SASS讲起 SASS Sass(英文全称:Syntactically Awesome Stylesheets)是一个最初由Hamp ...
- Sass学习笔记之入门篇
Sass又名SCSS,是CSS预处理器之一,,它能用来清晰地.结构化地描述文件样式,有着比普通 CSS 更加强大的功能. Sass 能够提供更简洁.更优雅的语法,同时提供多种功能来创建可维护和管理的样 ...
- Ionic2学习笔记(6):Navigation
作者:Grey 原文地址: http://www.cnblogs.com/greyzeng/p/5551535.html Ionic2中创建一个页面很方便,在页面之间相互切换也很方 ...
- Ionic2学习笔记(1):新建一个页面
作者:Grey 原文地址: http://www.cnblogs.com/greyzeng/p/5532323.html 新建一个页面: 借上一篇中的HelloWorl ...
- Sass学习笔记(补充)
阅读目录 1. Sass和SCSS的区别 2. @while循环 3. @at-root 4. @content 5. 凸显注释 6. CSS输出样式 7. 重置浏览器样式 8. Sass调试和@de ...
- sass个人学习笔记
Materliu 在慕课的视频: http://www.imooc.com/learn/364 . http://www.imooc.com/wiki/371 sass入门:http://www.w3 ...
- Ruby学习笔记4: 动态web app的建立
Ruby学习笔记4: 动态web app的建立 We will first build the Categories page. This page contains topics like Art, ...
- Angular6 学习笔记——内容投影, ViewChild和ContentChild
angular6.x系列的学习笔记记录,仍在不断完善中,学习地址: https://www.angular.cn/guide/template-syntax http://www.ngfans.net ...
随机推荐
- Python非递归遍历多叉树
class Queue: def __init__(self,max_size): self.max_size = int(max_size) self.queue = [] def put(self ...
- VcCallC#_02
1.VC代码:(vs2013运行正常) // ConsoleApplication_CallCS.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h&quo ...
- U3D协程yield的使用和理解
部分内容参考网址:http://blog.csdn.net/huang9012/article/details/29595747 Win7+U3D 4.6.7 1.在c#中使用①首选需要定义一个返回值 ...
- Codeforces D - High Load
D - High Load 因为要出口节点距离最小,所以除了根节点(根节点连接k个儿子)其他节点的儿子只能有一个,其他情况下的距离都比这个长,因为如果不是这样,那么根节点连接的子树数量就小与k,那么每 ...
- Codeforces 834D - The Bakery(dp+线段树)
834D - The Bakery 思路:dp[i][j]表示到第j个数为止分成i段的最大总和值. dp[i][j]=max{dp[i-1][x]+c(x+1,j)(i-1≤x≤j-1)},c(x+1 ...
- html生成缩略图来预览解决方案
html生成缩略图来预览解决方案 一.总结 一句话总结:先将html转化为canvas,然后将canvas生成图片ajax上传到服务器,就可以了 html 转化 canvas 图片 上传 html2c ...
- C语言的的free和c++的delete的区别
首先free对应的是malloc:delete对应的是new:free用来释放malloc出来动态内存,delete用来释放new出来的动态内存空间. 应用的区别为: 1. 数组的时候int *p=( ...
- English trip V1 - 辅导课 VOCABULARY BRUSH UP(1-6) 词汇刷新 SA:Winona
1.How Do you Feel Now? 形容词 adj. = adjective Describe people and thi ...
- 在centos7上安装gcc、node.js(源码下载)
一.在centos7中安装node.js https://www.cnblogs.com/lpbottle/p/7733397.html 1.从源码下载Nodejs cd /usr/local/src ...
- hpu1165 贪心
1165: 最少的需求 [贪心] 时间限制: 1 Sec 内存限制: 128 MB 提交: 12 解决: 4 状态 题目描述 小Q开了一家餐厅,最近生意非常火爆. 假设有N N 个预订信息,第i i ...