css - SCSS – 如何从嵌套地图中获取特定值
问题描述
我正在尝试在 Buefy/Bulma 中自定义一些东西,我需要从 SCSS 地图中获得一些价值。我有以下内容:
$colors:
(
"white": (
$white,
$black
),
...
);
为了我的需要,我想从
@each $color in $colors {
.button.is-#{nth($color, 1)}.pulse {
position: relative;
&::after {
position: absolute;
content: nth($color, 2); //This returns both colors
...
现在我得到了两个($white,$black)。请帮忙——有没有办法只得到“$white”变量的结果?
非常感谢。
解决方案
密码笔
在这种情况下:
$white: #fff;
$black: #000;
$colors: (
white: (
$white,
$black,
),
);
@function returnColor($value) {
@return nth(map-get($colors, white), index(map-get($colors, white), $value));
}
body {
color: returnColor($white);
}
如果有多个嵌套映射,则:
$white: #fff;
$black: #000;
$red: red;
$invert: toLazy;
$colors: (
white: (
$white,
$black,
),
red: (
$red,
$invert,
),
);
@function returnColor($map, $value) {
@return nth(map-get($colors, $map), index(map-get($colors, $map), $value));
}
body {
background-color: returnColor(red, $invert);
color: returnColor(white, $white);
}
body {
background-color: toLazy;
color: #fff;
}
推荐阅读
- compilation - 如何使用 vscode 在 C++ 中编译程序?
- python-3.6 - 如何使用gstreamer输出rtsp流供多个客户端访问
- android - Firestore 数据库到 recyclerview 和搜索
- html - 如何删除网格上图像的额外空间
- python - Kivymd 无法将标签和文本字段保持在同一行
- mysql - 缺少数据库时如何迁移 wordpress 网站?
- android - Android 应用程序在 android 10 上崩溃
- swagger - swagger 编辑器 io 的默认格式是什么?
- powershell - 更改windows下哪些用户代码deploy执行脚本
- javascript - 砌体图像在 ajax 调用上未正确定位