variables - "$root: &" 在 sass 中是什么意思?
问题描述
我正在尝试了解 Splide 的 sass 文件(https://splidejs.com/)。
在许多文件中都有这样的代码
.splide {
$root: &;
&--ttb {
> #{$root}__pagination {
display: flex;
right: 1em;
bottom: 50%;
left: auto;
flex-direction: column;
transform: translate(0, 50%);
#{$root}__pagination__page {
width: $indicator-height;
height: $indicator-width;
}
}
}
}
什么$root: &;
手段?
解决方案
在您的代码段中,$root
只是变量的名称。
你可以给它另一个名字,比如$foo
.
$root: &
在这里等价于$root: .splide
as &
in sass 指代父选择器。
代表着:
.splide {
$root: &;
&--ttb {
> #{$root}__pagination {
display: flex;
right: 1em;
bottom: 50%;
left: auto;
flex-direction: column;
transform: translate(0, 50%);
#{$root}__pagination__page {
width: $indicator-height;
height: $indicator-width;
}
}
}
}
相当于:
.splide {
&--ttb {
> .splide__pagination {
display: flex;
right: 1em;
bottom: 50%;
left: auto;
flex-direction: column;
transform: translate(0, 50%);
.splide__pagination__page {
width: $indicator-height;
height: $indicator-width;
}
}
}
}
并将编译为:
.splide--ttb > .splide__pagination {}
.splide--ttb > .splide__pagination .splide__pagination__page {}
推荐阅读
- android - 在图像视图上应用 ColorFilter 的问题
- spring-boot - “空编码密码”调用没有客户端密码的令牌
- javascript - 如何从父组件更改子组件?
- javascript - 如何通过ajax单击按钮后从数据库中获取ID
- javascript - Kendo UI - 文本颜色更改点击取消
- javascript - 是否有通过索引从数组中获取字符串的函数
- javascript - 如何在时刻以小时格式减去两个小时格式
- wordpress - 如何在 WordPress 中检索 post_type 的查询列表?
- popup - 如何为gmail收件箱中使用inboxsdk创建的按钮添加操作?
- angular - 如何重新订购 Angular 材料表?