有什么方法可以阻止 CSS :hover text-decoration underline on child 吗?

发布于 2024-09-26 10:19:13 字数 1292 浏览 1 评论 0原文

可能的重复:
如何解决此 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 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    多彩岁月 2024-10-03 10:19:13

    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 with text-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 if p: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.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文