Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

关于scss mixin的疑惑

scss mixin和写一个全局的公共样式有什么区别?
优点在哪里,我感觉写一个全局的公共样式,用起来更简单啊


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

sass mixin 是直接在样式css引入、还可以动态传参,全局公共样式是在html引用,
个人觉得sass mixin相对于全局公共样式 页面上会更简洁,功能更强大
比如

全局公共样式:
.color{
    color:red;
}
.size{
    font-size:16px;
}
.size2{
    font-size:18px;
}
.active{
    background:#fff;
}
<div class="color size active"></div>
<div class="color size2 active"></div>

sass mixin:
@mixin color{
    color:red;
}
@mixin size($num){
    font-size:$num;
}
.active{
    background:#fff;
    @include color;
    @include size(16px);
}
.active2{
    background:#fff;
    @include color;
    @include size(18px);
}
<div class="active"></div>
<div class="active2"></div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...