更改所有链接状态相同颜色的 css
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8855413/
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
Change all link states same color css
提问by David19801
I have a spanned class called "tomato".
我有一个名为“番茄”的跨类课程。
My css is:
我的CSS是:
.tomato a:link {color:#FF0000;} /* unvisited link */
.tomato a:visited {color:#FF0000;} /* visited link */
.tomato a:hover {color:#FF0000;} /* mouse over link */
.tomato a:active {color:#FF0000;} /* selected link */
Is there a way I can combine all these into a smaller piece of code? (I want the link to be red in all states)
有没有办法可以将所有这些组合成一小段代码?(我希望链接在所有州都是红色的)
采纳答案by AlphaMale
This is the shortest
, I don't think you can do it any shorter than:
这是shortest
,我认为你不能比以下更短:
.tomato a:link, .tomato a:visited, .tomato a:hover, .tomato a:active { color:#FF0000; }
OR
或者
.tomato { a:link, a:visited, a:hover, a:active { color:#FF00000; } }
Hope this helps.
希望这可以帮助。
回答by Grace Shao
.tomato a:link,
.tomato a:visited,
.tomato a:hover,
.tomato a:active {
color:#F00;
}
Note, the color HEX could be abbreviated, too. :)
请注意,颜色 HEX 也可以缩写。:)
If you choose to use a CSS framework to organize your CSS such as LESS, it could be much simpler than the above:
如果你选择使用一个 CSS 框架来组织你的 CSS,比如 LESS,它可能比上面的简单得多:
.tomato {
a:link,
a:visited,
a:hover,
a:active {
color:#F00;
}
}
回答by systemaddict
It is actually best to use the attribute selector. In this case it would be:
实际上最好使用属性选择器。在这种情况下,它将是:
.tomato a[href]{color:#F00;}
or if you must:
或者如果您必须:
.tomato [href]{color:#F00;}