gpt4 book ai didi

jquery - 使用 JQuery 折叠菜单

转载 作者:行者123 更新时间:2023-12-01 06:06:52 26 4
gpt4 key购买 nike

我正在开发一个需要展开和折叠的 JQuery 菜单。但是,我在让子菜单按我想要的方式排列时遇到一些问题。基本上,我希望子菜单项与顶部菜单项一致。然而,就目前情况而言,整个子菜单项都是缩进的。我的代码如下所示:

HTML

<ul id="theMenu"> 
<li><a title="open or close this section" href="#">Info</a>
<ul>
<li><a href="#">Basic</a></li>
<li><a href="#">Advanced</a></li>
</ul>
</li>

<li><a title="open or close this section" href="#">Documents</a>
<ul>
<li><a href="#">Newsletters</a></li>
<li><a href="#">Policies and Procedures</a></li>
<li><a href="#">job Descriptions</a></li>
</ul>
</li>
</ul>

JavaScript

$(document).ready(function () {
$("#theMenu > li > a").not(":first").find("+ ul").slideUp(1);
$("#theMenu > li > a").click(function () {
$(this).find("+ ul").slideToggle("fast");
});
});

CSS

#theMenu, #theMenu ul { list-style:none; width:15em; }
#theMenu a { background:#F6F6F6; color:#010101;
display:block; font-weight:bold; padding:0.5em 1em; text-decoration:none;
border:1px solid #DFDFDF;
}
#theMenu ul a { background:#F6F6F6; color:#010101;
font-weight:normal; text-decoration:none;
}
#theMenu ul a:hover { background:#F0EBE1; text-decoration:underline; color:#711515; }

如何使子菜单与根菜单的左边缘齐平?

谢谢!

添加:演示 here

最佳答案

#theMenu, #theMenu ul { list-style:none; width:15em; }

#theMenu, #theMenu ul { list-style:none; width:15em;margin:0;padding:0; }

关于jquery - 使用 JQuery 折叠菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4946309/

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