I need to style my button component in 5 states with differently colored icon and use for this following 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");
}
such items differs in pseudoclasses related to #add-username-to-list. I tried to switch entire css file to scss and wanted to optimize this style but I was not able move further than:
#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");
}
}
}
Is it possible to do something like this?
#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");
}
...
}
}
}
where &&
will represents grandparent selector #add-username-to-list
.
I also tried to apply pattern #{$grandparent}:tmp $
but the result selector looked like this: #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");
}
...
}
}
}
Any advice whether is this possible?
You can use interpolation to print out your grandparent selector (note the @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); }
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With