scss的混入和继承,以及for,each循环

本文详细介绍了 Sass 预处理器的使用,包括变量、混合、嵌套选择器、循环与条件语句等特性。通过实例展示了如何创建可复用的 CSS 代码,并解释了编译过程。此外,还探讨了导入与扩展(@import 和 @extend)的用法及其对最终 CSS 的影响。
摘要由CSDN通过智能技术生成

码云代码仓:https://gitee.com/songjinyang/scss
index.scss

$color-red:red;
$color-blue:blue;
@mixin flex($direction,$jus-con:'',$ali-itm:'') {
    display: flex;
    @if $direction=='column' {
        flex-direction: column;
    }@else {
        flex-direction: 'xxx';
    }
    justify-content: $jus-con;
    align-items: $ali-itm;
}
.ext{
    color: green;
}
h1.ext {
    font-size: 22px;
}
.father {
    color: $color-red;
    .sonOne {
        @import "./imp.scss";

        background-color: $color-blue;
        .one1 {
            color: $color-blue;
            @extend .ext; 
        }
    }
    .sonTwo {
        // @include flex('row','flex-end','center');
        @include flex($direction:'',$jus-con:center,$ali-itm:center);
        background-color: $color-blue;
        @extend .ext;
    }
    
}
// 插值语句
$border:border;
.#{$border} {
    #{border}:1px solid yellow;
}
// for
@for $i from 1 through 3 {
    .item#{$i} {
        width: 1px*#{$i};
    }
}
// each
@each $item in a,b,c,d,e {
    .test#{$item} {
        color: red;
    }
}
@each $item,$color in (color,red),('width','2px'),('height','3px') {
    .cc {
        #{$item}:#{$color};
    }
}

imp.scss

$color-blue:yellow;

最后编译css为

.ext, .father .sonOne .one1, .father .sonTwo {
  color: green;
}

h1.ext, .father .sonOne h1.one1, .father h1.sonTwo {
  font-size: 22px;
}

.father {
  color: red;
}

.father .sonOne {
  background-color: yellow;
}

.father .sonOne .one1 {
  color: yellow;
}

.father .sonTwo {
  display: flex;
  flex-direction: 'xxx';
  justify-content: center;
  align-items: center;
  background-color: blue;
}

.border {
  border: 1px solid yellow;
}

.item1 {
  width: 1px*1;
}

.item2 {
  width: 1px*2;
}

.item3 {
  width: 1px*3;
}

.testa {
  color: red;
}

.testb {
  color: red;
}

.testc {
  color: red;
}

.testd {
  color: red;
}

.teste {
  color: red;
}

.cc {
  color: red;
}

.cc {
  width: 2px;
}

.cc {
  height: 3px;
}
/*# sourceMappingURL=index.min.css.map */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值