我正在使用Bootstrap collapse实现一个带有子菜单的垂直菜单。我可以通过单击一个字体很棒的箭头图标来切换子菜单内容的可见性。当箭头指向下方时,子菜单会显示,而当箭头指向上方时,子菜单会隐藏。
一切都很好,除了当我希望我所有的子菜单最初都被展开的时候。箭头在应该指向上的时候指向下。
我的代码:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://kit.fontawesome.com/d45e7e578e.js" crossorigin="anonymous"></script>
<ul class="mymenu nav flex-column">
<li class="nav-item">
<a class="nav-link collapsed" href="#submenu1" data-toggle="collapse" data-target="#submenu1">
<span>Menu Item</span>
</a>
<div class="collapse show" id="submenu1" aria-expanded="true">
<ul class="flex-column nav">
<li class="nav-item">
<a class="nav-link py-0" href="#">
<span>Submenu Item</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="#">
<span>Submenu Item</span>
</a>
</li>
</ul>
</div>
</li>
<li class="nav-item">
<a class="nav-link collapsed" href="#submenu2" data-toggle="collapse" data-target="#submenu2">
<span>Menu Item</span>
</a>
<div class="collapse show" id="submenu2" aria-expanded="true">
<ul class="flex-column nav">
<li class="nav-item">
<a class="nav-link py-0" href="#">
<span>Submenu Item</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="#">
<span>Submenu Item</span>
</a>
</li>
</ul>
</div>
</li>
</ul>
CSS:
.nav-item{
position: relative;
}
.nav-link[data-toggle].collapsed:after {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f078";
color: #444444;
position: absolute;
right: 10px;
}
.nav-link[data-toggle]:not(.collapsed):after {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f077";
color: #444444;
position: absolute;
right: 10px;
}
如有任何建议,我们将不胜感激
2条答案
按热度按时间5lhxktic1#
由于
collapsed
类,在删除
collapsed
类x一个一个一个一个x一个一个二个x
hgc7kmma2#