更少的 css,嵌套的属性,:hover::after
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16796570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:02:38 来源:igfitidea点击:
Less css, nested attributes, :hover::after
提问by Philip
Is it possible to do this with less?
有没有可能用更少的钱来做到这一点?
a {
&:after {
background: red;
}
&:hover {
&:after {
background: blue;
}
}
}
I can't get the :after
to change color when hovering over a
?
:after
悬停时我无法改变颜色a
?
回答by Robert McKee
The following works fine for me:
以下对我来说很好用:
a {
&:after {
content:'a';
background: red;
}
&:hover {
&:after {
background: blue;
}
}
}
My LESS-enabled editor, compiled that to:
我启用 LESS 的编辑器将其编译为:
a:after {
content: 'a';
background: red;
}
a:hover:after {
background: blue;
}
Which does work.
哪个有效。
回答by Sunil Rajput
This is also work fine for me : -
这对我来说也很好用:-
a{
&:after{
background: red;
content: "Hover Text"
}
&:hover{
&:after{
background: yellow;
}
}
}
And My terminal Compile that to:-
我的终端将其编译为:-
a:after {
background: red;
content: "Hover Text";
}
a:hover:after {
background: yellow;
}
回答by miber
a {
&:after {
background: red;
}
&:hover,
&:after {
background: blue;
}
}
This is okay now :P
现在好了 :P