前端开发中scss 常用的特性

前言

此文章介绍一下常用的scss在开发中经常用到的一些特性

scss

什么是scss

    世界上最成熟、最稳定、最强大的专业级CSS扩展语言!

scss 和 sass 区别

scss 是 sass 的升级版,完全兼容sass的特性,又增加了其他特性。

在这里插入图片描述

特性

变量

!default 声明默认变量,重新定义可以覆盖默认变量:$color = pink

    $color: red !default

局部变量可以覆盖全局变量;局部变量加上:!global 可以变成全局变量

$height: 200px // 全局变量
 body {
     $height: 300px; //局部变量
     height:$height
   }

嵌套引用

$left: left
 .box {
     border-#{$left}:1px solid #333
   }

继承@extend

.box {
  color: pink;
  border: 1px dashed purple;
}
.box1 {
	@extend .box 
}

@mixin

/*无默认值*/
@mixin normalStyle {
	width: 300px;
  height: 200px;
}
/*有默认值*/
@mixin normalStyle2 ($width,$height){
	width: $width;
  height: $height;
}
.box {
  @include normalStyle
}
.box2 {
  @include normalStyle(300px,200px)
}

条件语句

$type: list
.box {
   p {
    @if $type == list{
      color: pink;
    } @else {
      color: purple;
    }
  }
}

@function

@function double($sn) {
  @return $sn*2
}
.box {
  width: double(200px)
}

循环

@for $i from 1 through 3 {
  .item-#{$i} {
    width: 200px * $i;
    height: 100px;
    border: solid 1px #333;
  }
}

在这里插入图片描述

后记

这些只是开发中用到的,还有其他的不常用的特性,没有记录了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值