仅选择具有特定类别的最嵌套列表项

编程入门 行业动态 更新时间:2024-10-10 08:23:30
本文介绍了仅选择具有特定类别的最嵌套列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我只需要选择ul结构中最深的li.active.在这种情况下,该值为Další kategorie.我找不到CSS唯一的解决方案.可能吗?谢谢.

I need to select only the the deepest li.active in the ul structure. In this case that would be Další kategorie. I cannot find css only solution. Is it even possible? Thanks.

<nav class="smenu"> <ul> <li class="predsednictvo first"><a href="/cs/csmg/predsednictvo/"><span>PŘEDSEDNICTVO</span></a></li> <li class="sub active komise"><a href="/cs/csmg/komise/"><span>KOMISE</span></a> <ul> <li class="kategorie first"><a href="/cs/csmg/komise/kategorie/"><span>Kategorie</span></a></li> <li class="active dalsi-kategorie last"><a href="/cs/csmg/komise/dalsi-kategorie/"><span>Další kategorie</span></a></li> // I'need to select only this element (current page) </ul> </li> <li class="kontakty"><a href="/cs/csmg/kontakty/"><span>KONTAKTY</span></a></li> <li class="reprezentace last"><a href="/cs/csmg/reprezentace/"><span>REPREZENTACE</span></a></li> </ul> </nav>

推荐答案

更新: 目前,这仅通过CSS是不可能的.孩子不能影响他们的父母.一旦CSS4 :has()选择器从工作草案变成规范,并且浏览器开始实施它,这将是可能的.当前状态: drafts.c​​sswg/selectors-4/#relational

Update: This is currently not possible only via CSS. Children cannot affect thei parents. It will be possible once CSS4 :has() selector gets from working draft to specification and browsers starts implementing it. Current state: drafts.csswg/selectors-4/#relational

原始答案: 好的,如果不可能仅通过CSS,那就是我要这样做的方式:

Original answer: Ok, if it's not possible only via CSS, that's how I would do it:

$('li.active:not(:has(li.active))').addClass('deepest');

更多推荐

仅选择具有特定类别的最嵌套列表项

本文发布于:2023-11-28 20:12:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   类别   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!