gpt4 book ai didi

javascript - 我可以将 bootstrap 折叠更改为仅在单击图标时显示/展开吗?

转载 作者:行者123 更新时间:2023-11-30 09:42:27 26 4
gpt4 key购买 nike

我正在制作一种选择框,他们可以在其中选择类别。我想要它,这样他们就可以选择任何项目。为此,我需要在单击任何地方时仅在单击 + 或 - 图标时不显示/隐藏项目。希望这是有道理的。我试着移动 data-toggle="collapse"以为我可以把它放在我的图标上,但它最终坏了。

.list-group.list-group-root {
padding: 0;
overflow: hidden;
}

.list-group.list-group-root .list-group {
margin-bottom: 0;
}

.list-group.list-group-root .list-group-item {
border-radius: 0;
border-width: 1px 0 0 0;
font-size: 18px;
}

.list-group.list-group-root > .list-group-item:first-child {
border-top-width: 0;
}

.list-group.list-group-root > .list-group > .list-group-item {
padding-left: 30px;
font-size: 16px;
}

.list-group.list-group-root > .list-group > .list-group > .list-group-item {
padding-left: 45px;
font-size: 14px;
}

.list-group-item .glyphicon {
margin-right: 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="list-group list-group-root well">

<a href="#item-1" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 1
</a>
<div class="list-group collapse" id="item-1">

<a href="#item-1-1" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 1.1
</a>
<div class="list-group collapse" id="item-1-1">
<a href="#" class="list-group-item">Item 1.1.1</a>
<a href="#" class="list-group-item">Item 1.1.2</a>
<a href="#" class="list-group-item">Item 1.1.3</a>
</div>

<a href="#item-1-2" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 1.2
</a>
<div class="list-group collapse" id="item-1-2">
<a href="#" class="list-group-item">Item 1.2.1</a>
<a href="#" class="list-group-item">Item 1.2.2</a>
<a href="#" class="list-group-item">Item 1.2.3</a>
</div>

<a href="#item-1-3" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 1.3
</a>
<div class="list-group collapse" id="item-1-3">
<a href="#" class="list-group-item">Item 1.3.1</a>
<a href="#" class="list-group-item">Item 1.3.2</a>
<a href="#" class="list-group-item">Item 1.3.3</a>
</div>

</div>

<a href="#item-2" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 2
</a>
<div class="list-group collapse" id="item-2">

<a href="#item-2-1" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 2.1
</a>
<div class="list-group collapse" id="item-2-1">
<a href="#" class="list-group-item">Item 2.1.1</a>
<a href="#" class="list-group-item">Item 2.1.2</a>
<a href="#" class="list-group-item">Item 2.1.3</a>
</div>

<a href="#item-2-2" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 2.2
</a>
<div class="list-group collapse" id="item-2-2">
<a href="#" class="list-group-item">Item 2.2.1</a>
<a href="#" class="list-group-item">Item 2.2.2</a>
<a href="#" class="list-group-item">Item 2.2.3</a>
</div>

<a href="#item-2-3" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 2.3
</a>
<div class="list-group collapse" id="item-2-3">
<a href="#" class="list-group-item">Item 2.3.1</a>
<a href="#" class="list-group-item">Item 2.3.2</a>
<a href="#" class="list-group-item">Item 2.3.3</a>
</div>

</div>


<a href="#item-3" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 3
</a>
<div class="list-group collapse" id="item-3">

<a href="#item-3-1" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 3.1
</a>
<div class="list-group collapse" id="item-3-1">
<a href="#" class="list-group-item">Item 3.1.1</a>
<a href="#" class="list-group-item">Item 3.1.2</a>
<a href="#" class="list-group-item">Item 3.1.3</a>
</div>

<a href="#item-3-2" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 3.2
</a>
<div class="list-group collapse" id="item-3-2">
<a href="#" class="list-group-item">Item 3.2.1</a>
<a href="#" class="list-group-item">Item 3.2.2</a>
<a href="#" class="list-group-item">Item 3.2.3</a>
</div>

<a href="#item-3-3" class="list-group-item" data-toggle="collapse">
<i class="fa fa-plus pull-right"></i>Item 3.3
</a>
<div class="list-group collapse" id="item-3-3">
<a href="#" class="list-group-item">Item 3.3.1</a>
<a href="#" class="list-group-item">Item 3.3.2</a>
<a href="#" class="list-group-item">Item 3.3.3</a>
</div>

</div>

</div><!-- end category list -->

最佳答案

这是一种方法..

(正如@Justin L. 所解释的那样)

.list-group.list-group-root {
padding: 0;
overflow: hidden;
}

.list-group.list-group-root .list-group {
margin-bottom: 0;
}

.list-group.list-group-root .list-group-item {
border-radius: 0;
border-width: 1px 0 0 0;
font-size: 18px;
}

.list-group.list-group-root > .list-group-item:first-child {
border-top-width: 0;
}

.list-group.list-group-root > .list-group > .list-group-item {
padding-left: 30px;
font-size: 16px;
}

.list-group.list-group-root > .list-group > .list-group > .list-group-item {
padding-left: 45px;
font-size: 14px;
}

.list-group-item .glyphicon {
margin-right: 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="list-group list-group-root well">

<span class="list-group-item" >
<a href="#item-1" data-toggle="collapse"><i class="fa fa-plus pull-right"></i></a> 1
</span>
<div class="list-group collapse" id="item-1">

<span class="list-group-item" >
<a href="#item-1-1" data-toggle="collapse"><i class="fa fa-plus pull-right"></i></a>Item 1.1
</span>
<div class="list-group collapse" id="item-1-1">
<a href="#" class="list-group-item">Item 1.1.1</a>
</div>

</div><!-- end category list -->

关于javascript - 我可以将 bootstrap 折叠更改为仅在单击图标时显示/展开吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40512892/

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