gpt4 book ai didi

jquery - 折叠文件夹

转载 作者:行者123 更新时间:2023-11-28 04:20:30 24 4
gpt4 key购买 nike

问题:我能够使用 css 创建一个可折叠的文件夹。

但是,如果进入第二页,我无法确定如何下推文件夹。目前,CSS 是如何工作的,如果在它下面的文件夹下面有一个文件夹,它就会重叠。我希望能够将文件夹下推到另一个文件夹下。

我提供了一张关于我所说内容的图片:

enter image description here

#primary_nav_wrap
{
margin-top:15px
}

#primary_nav_wrap ul
{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}

#primary_nav_wrap ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}

#primary_nav_wrap ul li
{
position:relative;
float:left;
margin:0;
padding:0
}

#primary_nav_wrap ul li.current-menu-item
{
background:#ddd
}

#primary_nav_wrap ul li:hover
{
background:#f6f6f6
}

#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}

#primary_nav_wrap ul ul li
{
float:none;
width:200px
}

#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px
}

#primary_nav_wrap ul ul ul
{
top:0;
left:100%
}

#primary_nav_wrap ul li:hover > ul
{
display:block
}
<nav id="primary_nav_wrap">
<ul>
<li style="margin-left:20px">
<a href="#">Controlled Substance Materials</a>
<ul>
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
<li><a href="#">Sub Menu 3</a></li>
<li><a href="#">Sub Menu 4</a>
<ul>
<li><a href="#">Deep Menu 1</a>
<ul>
<li><a href="#">Sub Deep 1</a></li>
<li><a href="#">Sub Deep 2</a></li>
<li><a href="#">Sub Deep 3</a></li>
<li><a href="#">Sub Deep 4</a></li>
</ul>
</li>
<li><a href="#">Deep Menu 2</a></li>
</ul>
</li>
<li><a href="#">Sub Menu 5</a></li>
</ul>
</li>
</ul>
</nav>
<nav id="primary_nav_wrap">
<ul>
<li style="margin-left:20px">
<a href="#">Controlled Substance Materials</a>
<ul>
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
<li><a href="#">Sub Menu 3</a></li>
<li><a href="#">Sub Menu 4</a>
<ul>
<li><a href="#">Deep Menu 1</a>
<ul>
<li><a href="#">Sub Deep 1</a></li>
<li><a href="#">Sub Deep 2</a></li>
<li><a href="#">Sub Deep 3</a></li>
<li><a href="#">Sub Deep 4</a></li>
</ul>
</li>
<li><a href="#">Deep Menu 2</a></li>
</ul>
</li>
<li><a href="#">Sub Menu 5</a></li>
</ul>
</li>
</ul>
</nav>
<nav id="primary_nav_wrap">
<ul>
<li style="margin-left:20px">
<a href="#">Controlled Substance Materials</a>
<ul>
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
<li><a href="#">Sub Menu 3</a></li>
<li><a href="#">Sub Menu 4</a>
<ul>
<li><a href="#">Deep Menu 1</a>
<ul>
<li><a href="#">Sub Deep 1</a></li>
<li><a href="#">Sub Deep 2</a></li>
<li><a href="#">Sub Deep 3</a></li>
<li><a href="#">Sub Deep 4</a></li>
</ul>
</li>
<li><a href="#">Deep Menu 2</a></li>
</ul>
</li>
<li><a href="#">Sub Menu 5</a></li>
</ul>
</li>
</ul>
</nav>
<nav id="primary_nav_wrap">
<ul>
<li style="margin-left:20px">
<a href="#">Controlled Substance Materials</a>
<ul>
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
<li><a href="#">Sub Menu 3</a></li>
<li><a href="#">Sub Menu 4</a>
<ul>
<li><a href="#">Deep Menu 1</a>
<ul>
<li><a href="#">Sub Deep 1</a></li>
<li><a href="#">Sub Deep 2</a></li>
<li><a href="#">Sub Deep 3</a></li>
<li><a href="#">Sub Deep 4</a></li>
</ul>
</li>
<li><a href="#">Deep Menu 2</a></li>
</ul>
</li>
<li><a href="#">Sub Menu 5</a></li>
</ul>
</li>
</ul>
</nav>

最佳答案

如果我真的只想使用 CSS,我会这样做。我在 CSS 中加入了注释来解释我在做什么。

* {
font-family: sans-serif;
}

.collapsible {
list-style-type: none;
height: 24px; /* Fixed value for height */
overflow: hidden; /* hides the Sub-items */
background: rgba(0, 0, 0, 0.1);
padding: 6px;
width: 160px;
}
.collapsible:hover {
cursor: pointer !important; /* For easier user interaction */
height: auto; /* On hover, the full menu is revealed */
}
.collapsible li {
font-size: 16px;
line-height: 26px; /* Line height is just greater than the height of the menu before hover to make sure it's hidden */
}
.collapsible li:first-child {
padding-bottom: 0.6em;
}
.collapsible li:not(:first-child) {
padding-left: 1.2em;
}
.folder-title {
font-weight: bold;
}
<ul class="collapsible">
<li class="folder-title">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTVYiGGwOeG9r4CWQgttlHyby_BMVa_mx7qZW9yFt5nFifCvRtj_Kt40Q" style="height: 16px; vertical-align: middle;">&nbsp;Folder Title</li>
<li>Sub-item 1</li>
<li>Sub-item 2</li>
<li>Sub-item 3</li>
</ul>

<ul class="collapsible">
<li class="folder-title">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTVYiGGwOeG9r4CWQgttlHyby_BMVa_mx7qZW9yFt5nFifCvRtj_Kt40Q" style="height: 16px; vertical-align: middle;">&nbsp;Folder Title</li>
<li>Sub-item 1</li>
<li>Sub-item 2</li>
<li>Sub-item 3</li>
</ul>

<ul class="collapsible">
<li class="folder-title">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTVYiGGwOeG9r4CWQgttlHyby_BMVa_mx7qZW9yFt5nFifCvRtj_Kt40Q" style="height: 16px; vertical-align: middle;">&nbsp;Folder Title</li>
<li>Sub-item 1</li>
<li>Sub-item 2</li>
<li>Sub-item 3</li>
</ul>


<ul class="collapsible">
<li class="folder-title">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTVYiGGwOeG9r4CWQgttlHyby_BMVa_mx7qZW9yFt5nFifCvRtj_Kt40Q" style="height: 16px; vertical-align: middle;">&nbsp;Folder Title</li>
<li>Sub-item 1</li>
<li>Sub-item 2</li>
<li>Sub-item 3</li>
</ul>

基本上,使用 overflow: hidden;和一个固定的 height隐藏其余 <li> 的值元素,并使用 :hover状态来揭示它们。高度的变化也会将其他文件夹向下推。

关于jquery - 折叠文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42231351/

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