Having just started learning HTML and CSS, I wanted to create a vertical navigation bar with sub-sub menus. After some research, I found a code snippet that I modified to suit my needs. Below is the updated code:
#main-menu {
background-color: #2E3039;
}
.list-group-item {
background-color: #2E3039;
border: none;
}
a.list-group-item {
color: rgb(22, 21, 21);
}
a.list-group-item:hover,
a.list-group-item:focus {
background-color: #43D5B1;
}
a.list-group-item.active,
a.list-group-item.active:hover,
a.list-group-item.active:focus {
color: #FFF;
background-color: #43D5B1;
border: none;
}
.list-group-item:first-child,
.list-group-item:last-child {
border-radius: 0;
}
.list-group-level1 .list-group-item {
padding-left:30px;
}
.list-group-level2 .list-group-item {
padding-left:60px;
}
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="side2.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-3">
<!-- column1, Vertical Dropdown Menu -->
<div id="main-menu" class="list-group">
<a href="#sub-menu" class="list-group-item active" data-toggle="collapse" data-parent="#main-menu">Item 1 <span class="caret"></span></a>
<div class="collapse list-group-level1" id="sub-menu">
<a href="#" class="list-group-item" data-parent="#sub-menu">Sub Item 1</a>
<a href="#" class="list-group-item" data-parent="#sub-menu">Sub Item 2</a>
<a href="#sub-sub-menu" class="list-group-item" data-toggle="collapse" data-parent="#sub-menu">Sub Item 3 <span class="caret"></span></a>
<div class="collapse list-group-level2" id="sub-sub-menu">
<a href="#" class="list-group-item" data-parent="#sub-sub-menu">Sub Sub Item 1</a>
<a href="#" class="list-group-item" data-parent="#sub-sub-menu">Sub Sub Item 2</a>
<a href="#" class="list-group-item" data-parent="#sub-sub-menu">Sub Sub Item 3</a>
</div>
</div>
<a href="#" class="list-group-item">Item 2</a>
<a href="#" class="list-group-item">Item 3</a>
<a href="#" class="list-group-item">Item 4</a>
<a href="#" class="list-group-item">Item 5</a>
</div>
</div>
<div class="col-md-9">
<!-- column 2, content goes here... -->
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
I later attempted to add sub-sub menus to other sub menus as well by modifying the HTML file. However, when collapsing "Sub Item 1," it also collapses "Sub Item 2" and "Sub Item 3." Can someone assist me in adjusting the code so that only "Sub Item 1" collapses without affecting the other sub items? Thank you.