7

有谁知道是否可以防止在标签的子标签上加下划线,同时为标签的其余内容加下划线?

这是一个示例-您可以在JSFiddle上看到它。我已经尝试了我能想到的一切,但文本下划线继续应用于链接内的所有文本。我在 Chrome 上查看,但我确信这适用于所有浏览器。

a {
    font-size: 32px;           
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

a div {
    color: pink;
}

a:hover div,
a:active div,
a:focus div {
    text-decoration: none !important;
}​

<a href="http://news.bbc.co.uk">
<div class="inner">I don't want this bit underlined on hover. What's the big deal?</div>
This bit should be underlined on hover. Underlining here is fine. I have no objections to underlinining in this bit.
</a>​
4

1 回答 1

5

阅读这个类似的答案及其链接以获取更多信息:删除 :hover on :after elemets

http://jsfiddle.net/thirtydot/ygXy6/4/

CSS:

a {
    font-size: 32px;           
    text-decoration: none;
}

a:hover span {
    text-decoration: underline;
}

HTML:

<a href="http://news.bbc.co.uk">
    <div class="inner">I don't want this bit underlined on hover. What's the big deal?</div>
    <span>This bit should be underlined on hover. Underlining here is fine. I have no objections to underlinining in this bit.</span>
</a>​
于 2012-11-22T09:53:44.723 回答