这篇文章给大家分享的是有关sass常用操作的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
所有变量以$开头
$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;
}
}
简单理解,是可以重用的代码块,通过@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;
}
两种风格的注释
// 单行注释,编译后消失
/* 标准的CSS注释,会保留到编译后的代码中 */
如果重要的注释,压缩编译后还想保留,可在 /* 后面加上 !
/*!
重要注释,压缩编译也不会消失
*/
感谢各位的阅读!关于“sass常用操作的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。