我需要使用不同颜色的图标将按钮组件设置为 5 种状态,并用于以下 css
#add-member-dialog #add-username-to-list .to-list-button-icon:before {
content: url("../images/func_personplus_16_ena.png");
}
#add-member-dialog #add-username-to-list:hover .to-list-button-icon:before {
content: url("../images/func_personplus_16_hov.png");
}
#add-member-dialog #add-username-to-list:disabled .to-list-button-icon:before {
content: url("../images/func_personplus_16_dis.png");
}
#add-member-dialog #add-username-to-list:active .to-list-button-icon:before {
content: url("../images/func_personplus_16_act.png");
}
#add-member-dialog #add-username-to-list:active:hover .to-list-button-icon:before {
content: url("../images/func_personplus_16_onb.png");
}
Run Code Online (Sandbox Code Playgroud)
这些项目在与 #add-username-to-list 相关的伪类中有所不同。我尝试将整个 css 文件切换为 scss 并想要优化这种样式,但我无法进一步推进:
#add-member-dialog {
#add-username-to-list {
.to-list-button-icon:before {
content: url("../images/func_personplus_16_ena.png");
}
&:hover .to-list-button-icon:before {
content: url("../images/func_personplus_16_hov.png");
}
&:disabled .to-list-button-icon:before {
content: url("../images/func_personplus_16_dis.png");
}
&:active .to-list-button-icon:before {
content: url("../images/func_personplus_16_act.png");
}
&:active:hover .to-list-button-icon:before {
content: url("../images/func_personplus_16_onb.png");
}
}
}
Run Code Online (Sandbox Code Playgroud)
可以做这样的事情吗?
#add-member-dialog {
#add-username-to-list {
.to-list-button-icon:before {
content: url("../images/func_personplus_16_ena.png");
&&:hover & {
content: url("../images/func_personplus_16_hov.png");
}
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
其中&&will 代表祖父母选择器#add-username-to-list。
我也尝试应用模式#{$grandparent}:tmp $,但结果选择器如下所示:#add-member-dialog #add-username-to-list:tmp #add-member-dialog #add-username-to-list .to-list-button-icon:before
#add-member-dialog {
#add-username-to-list {
$grandparent: &;
.to-list-button-icon:before {
content: url("../images/func_personplus_16_ena.png");
#{$grandparent}:hover & {
content: url("../images/func_personplus_16_hov.png");
}
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议这是否可能吗?
您可以使用插值来打印您的祖父母选择器(注意@at-root):
#add-member-dialog {
#add-username-to-list {
$g: &; // grandparent
$p: '../images/func_personplus_16_'; // icon path
@at-root {
.to-list-button-icon:before {
#{$g} & { content: url(#{$p}ena.png); }
#{$g}:hover & { content: url(#{$p}hov.png); }
#{$g}:disabled & { content: url(#{$p}dis.png); }
#{$g}:active & { content: url(#{$p}act.png); }
#{$g}:active:hover & { content: url(#{$p}onb.png); }
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5533 次 |
| 最近记录: |