gpt4 book ai didi

javascript - 我正在尝试选择一个嵌套的 ul,尝试使用 css 但遇到了问题

转载 作者:行者123 更新时间:2023-11-28 13:09:49 24 4
gpt4 key购买 nike

我有一个 cms 呈现我正在设计的网站的菜单,我需要选择父菜单项的子项。以下是代码的生成方式:

<div class="menu">
<ul>
<li></li>
<li><a href="" class="CurrentButton" ... />text</a>
<div>
<ul></ul>
</div>
</li>
</ul>
</div>

我已经尝试使用此 CSS 来尝试选择它,但除了显示之外,它还没有成功 :none;

.menu ul li div {
display: none;
}

.menu > ul > li > a.CurrentButton div {
display: block;
}

谁能看出我做错了什么? jquery函数会更容易吗?我是 jquery 的新手,所以我不确定如何为它编写函数。

当 li 中的 anchor 具有 CurrentButton 类时,我正在尝试选择 li 中的 div,如果 li 中的 anchor 没有该类,那么我希望它隐藏

最佳答案

您给出的两个示例都依赖于查找 .menu 元素,但您的代码中不存在任何元素。 现在可以了。

a.CurrentButton div 选择任何 a.CurrentButton内部 div。但是,您的 div 不在 a 中。试试这个:

.menu ul > li > a {
//selects all the as, but non of the divs
}

.menu ul > li > * {
//selects anything inside a 'li', both 'a's and 'div's
}

要选择 a.CurrentButton 之后的 div,请使用:

.menu ul li > a.CurrentButton + div {
//any 'div's that are directly after 'a.CurrentButton'
}

关于javascript - 我正在尝试选择一个嵌套的 ul,尝试使用 css 但遇到了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19387812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com