gpt4 book ai didi

css - 使用 SCSS 函数复制具有不同背景的多个类样式

转载 作者:行者123 更新时间:2023-11-28 15:51:33 25 4
gpt4 key购买 nike

我有一个相同的类列表,但需要在其中包含不同的背景引用:

    .name-one {
@include thumb-source;
background: url('../name-one.png') no-repeat;
}

.name-two {
@include thumb-source;
background: url('../name-two.png') no-repeat;
}

.name-three {
@include thumb-source;
background: url('../name-three.png') no-repeat;
}

and it goes on for a while ...

如您所见,类名也复制了文件名。我想知道是否有一种方法可以使用 scss 编写一个函数来传递一个包含我的类名的数组并显着减少重复?

最佳答案

你可以使用@each:

$list: "one", "two", "three";
@each $item in $list {
.name-#{$cat} {
@include thumb-source;
background: url('../name-#{$cat}.png') no-repeat;
}
}

@each Documentation

关于css - 使用 SCSS 函数复制具有不同背景的多个类样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23915450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com