看起来像图像按钮的链接不听颜色:css 中的指令
我有一个页面 http://www.problemio.com/problems/problem。 php, 你可以在右下角看到我有一个青色的图像。这实际上是一个链接,在该链接中我似乎无法让文本颜色显示为白色。
这是我的 CSS:
.button
{
display: block;
background: #4E9CAF;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
text-color: white;
font-weight: bold;
text-decoration: none;
}
a:button.visited
{
display: block;
background: #4E9CAF;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
text-color: white;
font-weight: bold;
text-decoration: none;
}
这是我如何使用 HTML 创建链接:
<a class="button" id="follow_problem" href="#" title="...">Follow Problem</a>
知道出了什么问题以及为什么链接的颜色不是白色吗?
I have a page at http://www.problemio.com/problems/problem.php,
and you see on the bottom-right I have a teal image. It is really a link and in that link I can't seem to get the text color to appear white.
Here is my CSS:
.button
{
display: block;
background: #4E9CAF;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
text-color: white;
font-weight: bold;
text-decoration: none;
}
a:button.visited
{
display: block;
background: #4E9CAF;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
text-color: white;
font-weight: bold;
text-decoration: none;
}
and here is how I make the link with HTML:
<a class="button" id="follow_problem" href="#" title="...">Follow Problem</a>
Any idea what is going wrong and why the color of the link isn't white?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您似乎正在尝试覆盖
a:link
类的样式尝试:选项 1:
这是您尝试覆盖的类:
您需要将
!important
添加到样式声明的末尾:选项 2:
您可以进一步定义
a:link
类规则:It appears that you're trying to override the styling of the
a:link
class Try:Option 1:
Here is the class you're trying to override:
You need to add
!important
to the end of your style declaration:Option 2:
You could further define the
a:link
class rules:这是因为
a:link
(第 95 行)比.button
(第 109 行)更具体。您可以通过将规则更改为
提示来修复它:
!important
可以工作,但这是一个愚蠢的解决方法,最终会给您带来麻烦,而且它实际上是一种误用 - http://www.w3.org/TR/CSS2/cascade.html#important-rules< /a>Firebug
或 Chrome 的inspect element
,用于检查影响给定元素的 css。That's because
a:link
(line 95) is more specific than.button
(line 109).You can fix it by changing the rule to
Tips:
!important
will work, it is a silly workaround that will eventually get you in trouble, and it is actually a misuse - http://www.w3.org/TR/CSS2/cascade.html#important-rulesFirebug
for Firefox, or Chrome'sinspect element
, to check the css affecting a given element.在您的
.button
类中,使用:color: white !important;
。出现此问题的原因是a
样式声明是在.button
声明之后应用的,实际上取消了您为链接的 color 属性而设置的颜色。使用!important
可确保将color
规则应用于任何其他规则。In your
.button
class, use this:color: white !important;
. The problem happens because thea
style declaration is applied after the.button
declaration, in effect cancelling the color you have set in favor of the link 's color property. Using!important
ensures thecolor
rule is applied over any other.这是因为 common_elements.css 中有另一个类的优先级高于 .button
尝试通过
!important
使您的 .button 具有更高的优先级That's because you have another class in common_elements.css that has higher priority than .button
Try making your .button more prioritized by
!important