sass 常用备忘案例详解
编程小助手
2024-04-02 17:21
短信预约 -IT技能 免费直播动态提醒
一、变量
所有变量以$开头
$font_size: 12px;
.container{
font-size: $font_size;
}
如果变量嵌套在字符串中,需要写在#{}中
$side : left;
.rounded {
border-#{$side}: 1px solid #000;
}
二、嵌套
层级嵌套
.container{
display: none;
.header{
width: 100%;
}
}
属性嵌套,注意,border后需要加上冒号:
.container {
border: {
width: 1px;
}
}
可以通过&引用父元素,常用在各种伪类
.link{
&:hover{
color: green;
}
}
三、mixin
简单理解,是可以重用的代码块,通过@include 命令
// mixin
@mixin focus_style {
outline: none;
}
div {
@include focus_style;
}
编译后生成
div {
outline: none; }
还可指定参数、缺省值
// 参数、缺省值
@mixin the_height($h: 200px) {
height: $h;
}
.box_default {
@include the_height;
}
.box_not_default{
@include the_height(100px);
}
编译后生成
.box_default {
height: 200px; }
.box_not_default {
height: 100px; }
四、继承
通过@extend,一个选择器可以继承另一个选择器的样式。例子如下
// 继承
.class1{
float: left;
}
.class2{
@extend .class1;
width: 200px;
}
编译后生成
.class1, .class2 {
float: left; }
.class2 {
width: 200px; }
五、运算
直接上例子
.container{
position: relative;
height: (200px/2);
width: 100px + 200px;
left: 50px * 2;
top: 50px - 10px;
}
编译后生成
.container {
position: relative;
height: 100px;
width: 300px;
left: 100px;
top: 40px; }
插入文件
用@import 来插入外部文件
@import "outer.scss";
也可插入普通css文件
@import "outer.css";
自定义函数
通过@function 来自定义函数
@function higher($h){
@return $h * 2;
}
.container{
height: higher(100px);
}
编译后输出
.container {
height: 200px;
}
注释
两种风格的注释
// 单行注释,编译后消失
如果重要的注释,压缩编译后还想保留,可在
参考:
http://www.ruanyifeng.com/blog/2012/06/sass.html
到此这篇关于sass 常用备忘案例详解的文章就介绍到这了,更多相关sass 常用备忘内容请搜索编程学习网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程学习网!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341