h3 和锚标记样式问题
我有以下 html 片段,可以在我的页面上正常工作:
<a href="url goes here" onclick="return ! window.open(this.href);"><h3>title goes here</h3></a>
使用以下 css
h3
{
font-family:verdana, arial, helvetica, sans-serif;
font-size:75%;
font-weight:bold;
font-style:normal;
text-decoration:none;
text-transform:none;
margin:0px;
padding:0px;
color:#2C6598;
}
但是,这不是有效的 xhtml,因为
标记不应位于 内。
标签。
当我将
标签移到
标签之外时,CSS 似乎不起作用,即由于某种原因它失去了样式。
例如:
<h3><a href="url goes here" onclick="return ! window.open(this.href);">title goes here</a></h3>
with:
h3
{
font-family:verdana, arial, helvetica, sans-serif;
font-size:75%;
font-weight:bold;
font-style:normal;
text-decoration:none;
text-transform:none;
margin:0px;
padding:0px;
color:#2C6598;
}
如何纠正这个问题?
I have the following html snippet which works correctly on my page:
<a href="url goes here" onclick="return ! window.open(this.href);"><h3>title goes here</h3></a>
using the following css
h3
{
font-family:verdana, arial, helvetica, sans-serif;
font-size:75%;
font-weight:bold;
font-style:normal;
text-decoration:none;
text-transform:none;
margin:0px;
padding:0px;
color:#2C6598;
}
However, this is not valid xhtml as the <h3>
tag should not be within a <a>
tag.
When I move the <h3>
tags outside of the <a>
tags, the css does not seem to work, i.e. it loses it's style for some reason.
For example:
<h3><a href="url goes here" onclick="return ! window.open(this.href);">title goes here</a></h3>
with:
h3
{
font-family:verdana, arial, helvetica, sans-serif;
font-size:75%;
font-weight:bold;
font-style:normal;
text-decoration:none;
text-transform:none;
margin:0px;
padding:0px;
color:#2C6598;
}
does not work the way it did with the <h3>
tag within the <a>
tags.
How can this be corrected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须在
标记上应用样式,
试试这个
You have to apply the style on
<a>
tagtry this
这是因为锚点的样式优先。您只需将样式表更改为
这应该可以解决问题。
This is because the styles for your anchor are taking precedence. You can simply change the stylesheet to
This should fix the problem.
我遇到了同样的问题,所以我只是简单地创建了一个新类,其中包含我希望最终文本具有的属性,所以它是这样的:
CSS:(没有“!important”就无法工作)
HTML:
I had the same problem, so I just simply made a new class with properties I wanted the final text to have, so it's something like that:
CSS: (it didn't work without "!important")
HTML:
我知道这篇文章很旧,但我遇到了这个问题。您可能必须满足任何可能覆盖您的样式的伪类,例如 a:visited 等。所以您还需要做的是:
I know this post is old but I encountered this problem. You may have to cater for any pseudo classes which may be overriding your styles e.g. a:visited etc. So what you would also need to to do is: