Here is the HTML code snippet I am working with:
<nav class="navbar navbar-expand-lg px-5 py-3 fixed-top navbar-dark">
<div>
<p id="navbar-brand-text">Some text</p>
<a class="navbar-brand smooth-scroll" href="#home">Brand text</a>
</div>
<button class="navbar-toggler btn-navbar-toggler-style" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon" id="navbar-toggler-icon-style"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link smooth-scroll" href="#home">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#home">Item 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#home">Item 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#home">Item 3</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#home">Item 4</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#home">Item 5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#home">Item 6</a>
</li>
</ul>
</div>
</nav>
Below is the corresponding style for the HTML elements:
.navbar {
transition: all .5s ease-in-out;
}
#navbar-brand-text {
color: white;
padding: 0;
margin: 0 0 5px 0;
font-size: 12px;
text-align: center;
text-transform: uppercase;
letter-spacing: 3px;
}
.navbar .navbar-brand {
padding: 0;
margin: 0;
text-transform: uppercase;
letter-spacing: 2px;
}
.navbar-nav .nav-item {
padding-left: 8px;
padding-right: 8px;
}
.navbar-dark .navbar-nav .nav-link {
color: white;
font-size: 14px;
text-transform: uppercase;
}
.navbar-dark .nav-item.active .nav-link,
.navbar-dark .nav-item:focus .nav-link,
.navbar-dark .nav-item:hover .nav-link {
color: #4CAF50;
}
.btn-navbar-toggler-style:hover {
background: rgba(0, 0, 0, 0.1);
}
/* PADDING */
.navbar-collapse.show {
padding-top: 30px;
}
Currently, when the navbar collapses, I noticed that the padding seems to be added too late as shown in this gif.
I am seeking advice on how to achieve the desired result and correctly add padding only when the navbar collapses. Your assistance will be highly appreciated. Thank you.