【发布时间】:2019-11-14 17:15:08
【问题描述】:
我需要在 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");
}
此类项目在与#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");
}
}
}
有可能做这样的事情吗?
#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");
}
...
}
}
}
其中&& 将代表祖父母选择器#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");
}
...
}
}
}
任何建议这是否可能?
【问题讨论】:
-
刚刚开始您的父级选择器概念。你必须找到另一种方式