Html 无法使用 CSS 更改字体颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14105233/
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
Can't Change Font Color With CSS?
提问by Lloyd Banks
I have the following HTML
我有以下 HTML
<div class = "left">
<div id = "links">
<a href = "none" style = "text-decoration: none"><b>About</b></a>
<br>
<a href = "none" style = "text-decoration: none"><b>Principals</b></a>
<br>
<a href = "none" style = "text-decoration: none"><b>Contact</b></a>
<br>
</div>
</div>?
and CSS
和 CSS
.left {
position: fixed;
top: 0px;
left: 0px;
width: 30%;
height: 100%;
background-color: #8EE5EE;
color: #000000;
}
#links {
position: relative;
top: 40%;
text-align: right;
font-family: "Verdana", "Arial Black", sans-serif;
font-size: 25px;
color: #000000;
}?
The color of my links should be black, but they are appearing as dark blue. What's wrong with this code?
我的链接的颜色应该是黑色,但它们显示为深蓝色。这段代码有什么问题?
Thanks!
谢谢!
回答by David says reinstate Monica
The problem you're having is that a
elements have a default style which doesn't inherit the color from the parent element. To force the inheritance of the color
property:
您遇到的问题是a
元素具有默认样式,该样式不会从父元素继承颜色。强制继承color
属性:
a {
color: #000; /* for browsers that don't support 'inherit' as a color value */
color: inherit;
}
回答by jesse_galley
Add this to your css:
将此添加到您的CSS:
#links a:link{
color: #000;
}
You can then add things like...
然后,您可以添加诸如...
#links a:visited{
color: #000;
}
#links a:hover{
color: #000;
}
#links a:active{
color: #000;
}
...to change the color of the link in different states as well.
...也可以更改不同状态下链接的颜色。
Some reading material on this: http://www.w3schools.com/css/css_link.asp
关于此的一些阅读材料:http: //www.w3schools.com/css/css_link.asp
回答by VLS
Add #links a { color: #000; }
to your CSS to style your links (or just a { color: #000; }
if you want this color to be global).
添加#links a { color: #000; }
到您的 CSS 以设置您的链接的样式(或者只是a { color: #000; }
您希望此颜色为全局颜色)。
回答by Jonathan Eckman
Try this
尝试这个
#links a:link, a:hover, a:visited, a:active {
color: #000000;
}
Heres some documentation.
继承人一些文件。