跨入具有不同样式的标签
在我的 HTML 代码中,我有一个继承了 span
标记的 a
标记。我现在的问题是如何实现 link 元素中的文本在悬停时带有下划线,而 span 元素则不带有下划线?
HTML:
<a class="tooltip" href="#">
Link, should be underlined on hover.
<span class="custom info">Span, shouldn't be underlined on hover.</span>
</a>
CSS:
/* General settings */
a { color: black; text-decoration: none }
a:visited { color: black; }
a:hover { color: #1af; text-decoration: underline }
/* End */
.tooltip {
position: relative;
}
.tooltip span {
display:none;
position: absolute;
white-space:nowrap;
border-radius: 5px 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 5px 5px rgba(0, 0,0, 0.1);
-moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
font-family: Calibri, Tahoma, Geneva, sans-serif;
margin-left: 0;
z-index: 1;
text-decoration: none;
}
a.tooltip:hover span {
display:block;
text-decoration: none;
}
In my HTML code I have a
tag with a span
tag inherited. My question is now how can I achieve that the text in the link-element will be underlined on hover and the span-element not?
HTML:
<a class="tooltip" href="#">
Link, should be underlined on hover.
<span class="custom info">Span, shouldn't be underlined on hover.</span>
</a>
CSS:
/* General settings */
a { color: black; text-decoration: none }
a:visited { color: black; }
a:hover { color: #1af; text-decoration: underline }
/* End */
.tooltip {
position: relative;
}
.tooltip span {
display:none;
position: absolute;
white-space:nowrap;
border-radius: 5px 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 5px 5px rgba(0, 0,0, 0.1);
-moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
font-family: Calibri, Tahoma, Geneva, sans-serif;
margin-left: 0;
z-index: 1;
text-decoration: none;
}
a.tooltip:hover span {
display:block;
text-decoration: none;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以添加另一个跨度(又名 HTML 的内联管道胶带)并将
:hover
样式移至该位置:并且:
演示:http://jsfiddle.net/ambigously/UWgcc/1/
你可能想重命名
hack
类,我只是诚实地说那。如果您只想摆弄
.tooltip
链接,那么您可以将其添加到上面:演示:
You could add another span (AKA HTML's inline duct tape) and move the
:hover
styling to that:And:
Demo: http://jsfiddle.net/ambiguous/UWgcc/1/
You'd probably want to rename the
hack
class, I was just being honest with that.If you only want to mess around with your
.tooltip
links, then you could add this to the above:Demo: http://jsfiddle.net/ambiguous/UWgcc/2/
一个更简单的解决方法
是删除文本装饰并将其替换为 border-bottom 属性。
演示:http://jsfiddle.net/UBj76/
a much easier workaround
removes the text decoration and replaces it with a border-bottom property.
Demo: http://jsfiddle.net/UBj76/