Html 从超链接中删除所有样式/格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8919682/
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
Remove ALL styling/formatting from hyperlinks
提问by SiteHopper
I'm creating a navigation menu with words with different colors (href
links). I would like the color NOT to change on any state (hover, visited etc).
我正在创建一个带有不同颜色的单词(href
链接)的导航菜单。我希望颜色不会在任何状态下改变(悬停、访问等)。
I know how to set the the colors for the different states, but I would like to know the code to just leave the text color (and any other styling/formatting) as it is.
我知道如何设置不同状态的颜色,但我想知道代码只保留文本颜色(和任何其他样式/格式)。
Any Suggestions?
有什么建议?
回答by Frxstrem
You can simply define a style for links, which would override a:hover
, a:visited
etc.:
你可以简单地定义样式的链接,这将覆盖a:hover
,a:visited
等:
a {
color: blue;
text-decoration: none; /* no underline */
}
You can also use the inherit
value if you want to use attributes from parent styles instead:
inherit
如果您想使用父样式的属性,也可以使用该值:
body {
color: blue;
}
a {
color: inherit; /* blue colors for links too */
text-decoration: inherit; /* no underline */
}
回答by SpoonNZ
As Chris said before me, just an a
should override. For example:
正如克里斯在我之前所说的那样,只是a
应该覆盖。例如:
a { color:red; }
a:hover { color:blue; }
.nav a { color:green; }
In this instance the .nav a
would ALWAYS be green, the :hover wouldn't apply to it.
在这种情况下,.nav a
永远是绿色的, :hover 不适用于它。
If there's some other rule affecting it, you COULD use !important
, but you shouldn't. It's a bad habit to fall into.
如果有其他规则影响它,您可以使用!important
,但您不应该使用。养成这种坏习惯。
.nav a { color:green !important; } /*I'm a bad person and shouldn't use !important */
Then it'll always be green, irrelevant of any other rule.
然后它将永远是绿色的,与任何其他规则无关。
回答by Chris
You can just use an a
selector in your stylesheet to define all states of an anchor/hyperlink. For example:
您可以a
在样式表中使用选择器来定义锚点/超链接的所有状态。例如:
a {
color: blue;
}
Would override all link styles and make all the states the colour blue.
将覆盖所有链接样式并使所有状态为蓝色。
回答by Danferth
if you state a.redLink{color:red;}
then to keep this on hover and such add a.redLink:hover{color:red;}
This will make sure no other hover states will change the color of your links
如果您声明a.redLink{color:red;}
然后将其保持在悬停状态,并且这样添加a.redLink:hover{color:red;}
这将确保没有其他悬停状态会改变您的链接的颜色