能否用更少的方式完成这个任务?
a {
&:after {
background: red;
}
&:hover {
&:after {
background: blue;
}
}
}
当我悬停在 a
上时,无法使 :after
改变颜色。
以下方法对我来说运作良好:
a {
&:after {
content:'a';
background: red;
}
&:hover {
&:after {
background: blue;
}
}
}
我的支持LESS的编辑器将其编译为:
a:after {
content: 'a';
background: red;
}
a:hover:after {
background: blue;
}
哪个确实有效。
a{
&:after{
background: red;
content: "Hover Text"
}
&:hover{
&:after{
background: yellow;
}
}
}
a:after {
background: red;
content: "Hover Text";
}
a:hover:after {
background: yellow;
}
a {
&:after {
background: red;
}
&:hover,
&:after {
background: blue;
}
}
现在这样就可以了 :P
content
生成了伪元素,这个信息在问题中缺失。 - BoltClock