Scss学习--关于Scss指令@if、@for...from...through...@each..in 、@while

13 篇文章 0 订阅

@if

条件判断语句
@if (compare1){
statement1
}@else if (compare2){
statement2
}…@else{
statementn
}
首先判断compare1中的语句
如果不满足则判断compare2中的语句
以此判断下去,直到第n条满足compare n语句时
那么就执行 statement n中的语句

$monster: duck;
p.normal{
    background-color: if(1==2,red,green);
    @if 1+2 != 3 {font-size:16px};
    @if $monster == chicken {
        color: red;
    }@else if $monster == duck{
        color: yellow;
    }
}

@for…from…through…

for循环语句
for var from index_start through index_end

@for $i from 1 through 3{
    .item-#{$i}{
        margin: #{$i};
    }
}

@each…in

in 后面可以跟map也可以跟list

$list_group:(green,red,purple,blue);
@each $modules in $list_group{
    $index:index($list_group,$modules);

    #{".item-"+$modules}{
        color:#{$modules} ;
    }
}

$dict:(background:red,font-size:18px);
#divnodeBox{
@each $protype,$value in $dict{
        #{$protype}:#{$value};
    }
}

@while

while compare{
statements;
}
如果compare为真那么就执行statement中的语句

$i:6;
@while $i>0{
    #{".item-"+$i}{
        font-size: #{$i}px;
    };
    $i:($i - 2);
}
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值