scss的基本使用方法

普通嵌套

.a {
    font-size: 20px;
    .b {
      background-color: #ff0000;
      color: #000000;
    }
}
//编译后
.a {
    font-size: 20px;
}
.a .b{
    background-color: #ff0000;
    color: #000000;
}

属性嵌套

.a{
    border{
        top:{
            width:5px;
        }
        left:{
            width:1px;
        }
    }
}
//编译后
.a{
    border-top:width:5px;
    border-left:width:5px;
}

父选择器

//例
<div class="home">
    <div class="home-title"></div>
    <div class="home-content"></div>
    <div class="home-footer"></div>
</div>
.home{
    &-title{
        background:red;
    }
    &-content{
        background:black;
    }
    &-footer{
        background:green;
    }
}
//编译后
.home-title{
    background:red;
}
.home-content{
    background:red;
}
.home-footer{
    background:red;
}

变量

$width:5px;
.a{
    width:$width;
}
//编译后
.a{
    width:5px;
}

插值

$name: a;
$border: border;
.#{$name} {
    #{$border}-color: blue;
}
//编译后
.a{
    border-color: blue;
}

混合

@mixin demo{
    weight:50px;
    height:50px;
}
.a{
    @include demo;
}
//编译后
.a{
    weight:50px;
    height:50px;
}

继承

.a{
    font-size:14px;
    height: 16px;
}
.b{
    @extend .a;
    border-width: 2px;
}
//编译后
.a{
    font-size:14px;
    height: 16px;
}
.b{
    font-size:14px;
    height: 16px;
    border-width: 2px;
}

函数

@function fontSize($data){
    @return $data/2 + px;
}
.a{
  font-size: fontSize(24);
}
//编译后
.a{
  font-size: 12px;
}

for循环

1. @for $i from start through end
@for $i from 1 through 3 {
  .item-#{$i} { width: 2em * $i; }
}
//编译后
.item-1 {
  width: 20px;
}
.item-2 {
  width: 40px;
}
.item-3 {
  width: 60px;
}
2. @for $i from start to end
@for $i from 1 to 3 {
  .item-#{$i} { width: 10px * $i; }
}
//编译后
.item-1 {
  width: 20px;
}
.item-2 {
  width: 40px;
}

$i 表示变量
start 表示起始值
end 表示结束值
总结:两种写法的区别就是,through包括end这个数,to不包括end这个数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值