I am currently designing a webpage with Bootstrap and have a fixed top navbar along with a side navbar that uses scrollspy for content navigation. However, as I scroll down the page, the side navbar remains static and does not move along. I would like both the top and side navbars to scroll together with the page for better user experience without having to scroll back up.
Any assistance on achieving this behavior is highly appreciated. Thank you in advance!
Below is my HTML code:
<!DOCTYPE html>
<html>
<head>
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<title>Historical Adventures</title>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark" style="background-color: #201d1f; position: sticky;" id="navbar">
<a class="navbar-brand" href="#" style="font-size: 22px">Historical Adventures</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle Navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link text-light" href="">Placeholder</a>
</li>
<li class="nav-item">
<a class="nav-link text-light" href="">Placeholder</a>
</li>
</ul>
</div>
</nav>
<!-- header -->
<header class="jumbotron jumbotron-fluid text-light" style="background-color: #262626;">
<div>
<center>
<h1 class="display-3">placeholder</h1>
<h5 class="lead">placeholder</h5>
</center>
</div>
</header>
<!-- body/content -->
<div class="container p-0 m-0">
<div class="row m-0 p-0">
<!-- side navbar -->
<div class="col-3 m-0 p-0" style="float: left; position: sticky;">
<nav id="side-navbar" class="navbar navbar-light flex-column p-3 ml-0" style="float: left; background-color: #333333
; border-radius: 10px;">
<nav class="nav nav-pills flex-column">
<div class="mt-2">
<a class="nav-link" href="#introduction">Introduction</a>
<a class="nav-link" href="#introduction2">Early Civilizations</a>
</div>
<div class="mt-2">
<a class="nav-link" href="#indusvalley">Indus-Valley Civilization</a>
<nav class="nav nav-pills flex-column ml-3"">
<a class="nav-link" href="#city-profile">City Profile</a>
<a class="nav-link" href="#trade-economy">Trade and Economy</a>
<a class="nav-link" href="#cultural-artifacts">Cultural Artifacts</a>
<a class="nav-link" href="#administration">Administration</a>
<a class="nav-link" href="#indus-script">Indus Script</a>
<a class="nav-link" href="#legacy">Legacy</a>
<a class="nav-link" href="#conclusion">Conclusion</a>
</nav>
</div>
</nav>
</nav>
</div>
<!-- main content -->
<div class="col-9" data-bs-spy="scroll" data-bs-target="#side-navbar" data-bs-offset="0" tabindex="0" data-bs-smooth-scroll="true">
<!-- content in here -->
</div>
</div>
</div>
<footer class="jumbotron jumbotron-fluid mb-0" style="background-color: #242424;">
<div>
<center>
<a href="#" class="m-1"><i class="fab fa-facebook text-light" style="font-size: 24px;"></i></a>
<a href="#" class="m-1"><i class="fab fa-instagram text-light" style="font-size: 24px;"></i></a>
<a href="#" class="m-1"><i class="fab fa- text-light" style="font-size: 24px;"></i></a>
</center>
</div>
<div style="background-color: #202020">
<h6 class="text-light"><a href="">Website Source Code</a></h6>
</div>
</footer>
</body>
</html>
Here's my CSS code:
html {
height: 100%;
width: 100%;
}
.nav-link:hover {
background-color: #2275e2;
border-radius: 5px;
color: whitesmoke;
}
Link to view the project on Codepen.io: https://codepen.io/AverageDogeEnjoyer/pen/vYbLzjw?editors=1010