SASS的@at-root (with:...)介绍

发现网上大部分都是在介绍@at-root的without功能,对于with功能介绍较少,简单来说就是without的相反情况。

对于大佬们来说可能不值一提,对于初入sass的初学者可能会有一些困扰。

正如@at-root (without:...)一样,@at-root(with:...)同样含有rule, media, all, supports四种选择。

以midea为例:

@media print {
    .parent1{
        color: blue;
        @at-root (with: media) {
            .child1{
                width: 100px;
            }
        }
    }
}
@media print {
    .parent2{
        color: blue;
        @at-root (with: rule) {
            .child2{
                width: 100px;
            }
        }
    }
}

转化后的代码为:


//使用with: media后 .child1被包含在@media中。
@media print {
  .parent1 {
    color: blue;
  }
  .child1 {
      width: 100px;
  }
}
//使用with: rule后 .child2被移出@media
@media print {
  .parent2 {
    color: blue;
  }
}
.child2 {
  width: 100px;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值