gpt4 book ai didi

jquery - 使用 Bootstrap 创建在点击时展开的垂直下拉菜单

转载 作者:行者123 更新时间:2023-11-28 11:35:19 25 4
gpt4 key购买 nike

我正在尝试创建一个在点击时展开的垂直菜单。单击每个元素时,应展开并显示 3 个链接。

这是初始布局:

点击所有元素后:

这是我目前的代码:

<!DOCTYPE html>
<body>
<div class="accordion" id="leftMenu">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-parent="#leftMenu"
data-toggle="collapse" href="#collapseTwo"><i class=
"icon-th"></i> Item 1</a>
</div>

<div class="accordion-body collapse" id="collapseTwo" style=
"height: 0px;">
<div class="accordion-inner">
<ul>
<li>This is one</li>
<li>This is two</li>
<li>This is Three</li>
</ul>
</div>
</div>
</div>

<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-parent="#leftMenu"
data-toggle="collapse" href="#collapseThree"><i class=
"icon-th-list"></i> Item 2</a>
</div>

<div class="accordion-body collapse" id="collapseThree" style=
"height: 0px;">
<div class="accordion-inner">
<ul>
<li>This is one</li>
<li>This is two</li>
<li>This is Three</li>
</ul>
</div>
</div>
</div>

<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-parent="#leftMenu"
data-toggle="collapse" href="#collapseFour"><i class=
"icon-list-alt"></i> Item 3</a>
</div>

<div class="accordion-body collapse" id="collapseFour" style=
"height: 0px;">
<div class="accordion-inner">
<ul>
<li>This is one</li>
<li>This is two</li>
<li>This is Three</li>
</ul>
</div>
</div>
</div>
</div>
</body>
</html>

我的扩展点击功能运行良好:jsFiddle Demo

问题是布局不完全符合我的要求。如上图所示,我想要一个主容器,菜单显示在容器内。

截至目前,它占据了整个屏幕宽度。并且子菜单项不会显示为 block 项。

为了避免问题因为“过于宽泛”而结束,我会让我的问题更精确:

  • 如何在仅占据屏幕宽度一部分的主容器内显示内容,而不是菜单占据整个屏幕宽度?

  • 如何显示嵌套的<li>作为一个类似盒子的 div(可点击)?

我对 Twitter bootstrap 完全陌生,我觉得我没有正确使用它。有人可以好心地告诉我如何真正做到这一点吗?

最佳答案

  1. 使用 Bootstrap 类“row”和“col”来控制 div 的宽度。
  2. 在可折叠 Accordion 或面板周围使用容器(如井类)。
  3. 查看this fiddle更多细节。这应该足以让您入门。

.well {
background-color: #FFFFFF;
}
ul.subMenu {
padding-left: 0px;
}
ul.subMenu li {
list-style-type: none;
text-align: left;
color: #000000;
border: 1px solid #e2e2e2;
margin-bottom: 4px;
}
<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.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-6">
<div class="well">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
Item #1
</a>
</h4>

</div>
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<ul class="subMenu">
<li>Item #1a</li>
<li>Item #1b</li>
<li>Item #1c</li>
</ul>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Item #2
</a>
</h4>

</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<ul class="subMenu">
<li>Item #2a</li>
<li>Item #2b</li>
<li>Item #2c</li>
</ul>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingThree">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Item #3
</a>
</h4>

</div>
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
<div class="panel-body">
<ul class="subMenu">
<li>Item #3a</li>
<li>Item #3b</li>
<li>Item #3c</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

关于jquery - 使用 Bootstrap 创建在点击时展开的垂直下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28923307/

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