有什么方法可以阻止 CSS :hover text-decoration underline on child 吗?
可能的重复:
如何解决此 CSS 文本装饰问题上班吗?
我正在使用 jquery 切换效果来显示或隐藏有关列表元素的更多信息:
jQuery(document).ready(function($) {
$("ul p").hide();
$("ul li").addClass("link");
$("ul li").click(function () {
$("p", this).toggle(300);
});
});
它可以很好地处理如下结构:
<ul>
<li>List element 1<p>Additional info 1</p></li>
<li>List element 2<p>Additional info 2</p></li>
</ul>
为了使其看起来“可点击”,我使用 css 设计 .link 的样式:
ul li.link {
color: #0066AA;
}
ul li.link:hover {
text-decoration: underline;
cursor: pointer;
}
但我不希望显示的文本看起来像链接,所以:
ul li.link p{
color: black;
text-decoration: none;
}
ul li.link p:hover {
cursor: text;
text-decoration: none;
}
但是
在悬停时仍然带有下划线(蓝色),尽管抛出了 text-decoration:none;在每一个自由空间!据我了解,这是因为子样式应用在父样式之上,所以我实际上所做的就是尝试在下划线之上放置“任何内容”并使其消失。
所以我的问题(最终!)是这样的:有没有什么方法可以去掉下划线,而无需将
从
Possible Duplicate:
How do I get this CSS text-decoration issue to work?
I'm using the jquery toggle effect to show or hide more information about list elements:
jQuery(document).ready(function($) {
$("ul p").hide();
$("ul li").addClass("link");
$("ul li").click(function () {
$("p", this).toggle(300);
});
});
which works fine with a structure like:
<ul>
<li>List element 1<p>Additional info 1</p></li>
<li>List element 2<p>Additional info 2</p></li>
</ul>
In order to make it look 'clickable' I'm styling .link with css:
ul li.link {
color: #0066AA;
}
ul li.link:hover {
text-decoration: underline;
cursor: pointer;
}
But I don't want the text that's revealed to look like a link so:
ul li.link p{
color: black;
text-decoration: none;
}
ul li.link p:hover {
cursor: text;
text-decoration: none;
}
But the <p>
is still underlined (in blue) on hover, despite throwing text-decoration:none; in every free space! From what I understand this is because the child styles are applied on top of the parent so what I'm effectively doing is trying to put 'nothing' on top of an underline and have it disappear.
So my question (eventually!) is this: Is there any way to get rid of that underline without taking the <p>
out of the <li>
(which I don't want to do for other reasons)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你能控制标记吗?我会将文本包装在
中的
中,并编写 CSS 以仅使用
text 来定位跨度-装饰:下划线;
。实际上,可点击区域应该是一个 href 为“#”的
元素。将点击处理程序绑定到锚点而不是 li。然后,您可以使用更多伪选择器,例如 a:visited ,并且记录了单击它的行为。我不确定
p:hover
是否真的应该在 CSS 中工作。我知道可以使用 jQuery 绑定到任何元素,但使用 CSS 我会坚持使用锚元素。Can you control the markup? I'd wrap the text inside the
<li/>
in a<span/>
and write the CSS to target just the span withtext-decoration:underline;
.Really though the clickable area should be an
<a/>
element with an href of "#". Bind a click handler to the anchor instead of the li. Then you have more pseudo-selectors like a:visited to work with and the behavior of clicking it is documented. I'm not sure ifp:hover
is actually supposed to work in CSS. I know it is possible to bind to any element with jQuery, but with CSS I'd stick with an anchor element.