html - 基于类的Sass宽度计算
问题描述
我正在玩sassmixins
并for
在其中循环,并想问处理这种情况的最佳方法是什么:我在 UI 上有一个类,它可以是基于名称或基于索引的。因此,让我们深入研究代码。
className={cn('stepper', { step-${activeIndex}
})}
解决方案1:
$steps: (
0: 0%,
1: 33%,
2: 66%,
3: 99%,
);
@mixin step-modifiers {
@each $name, $hex in $steps {
&.step-#{$name} {
width: $hex;
}
}
}
.stepper{
@include step-modifiers;
}
解决方案2:
$steps: 3;
@for $i from 0 through $steps {
.step-#{$i} {
width: (100% * $i / $steps);
}
}
预期结果
.stepper.step-0 {
width: 0%;
}
.stepper.step-1 {
width: 33%;
}
.stepper.step-2 {
width: 66%;
}
.stepper.step-3 {
width: 99%;
}
解决方案
推荐阅读
- javascript - 如何使用 OSM + d3-tile 绘制标记?
- firebase - Navigator.push() 在 Firebase 登录时失去了我的提供者
- python - 为什么不能在 Windows 上清理临时目录中的文件处理程序的文件?
- java - 为什么支持共享获取的同步器是独占获取的?
- c# - REST Web API:基于查询路径的 JSON 到 C# 对象
- docker - 如何在执行其入口点之前将 docker cp ssh 密钥添加到 docker 容器
- python - 使用 os.path.isfile() 删除目录
- machine-learning - 最佳强化学习优化器
- unity3d - 无法在 Unity 中构建 WebGL
- python - 带有 tee 命令的 Python 3.6 子进程模块返回码