After collapsing the navbar, the navbar items remain visible for a short period of time, as shown in the second image below. Here is the HTML code:
<nav class="navbar navbar-dark fixed-top" style="background-color: transparent;>
<a class="navbar-brand" href="#">Muhammad Yasir</a>
<button class="navbar-toggler navbar-toggler-right collapsed" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="my-1 mx-2 close">X</span>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Resume</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
This is the CSS code:
.navbar-toggler>.close {
display:inline;
color: white;
}
.navbar-toggler.collapsed>.close, .navbar-toggler:not(.collapsed)>.navbar-toggler-icon {
display:none;
}
Upon collapsing the navbarhttps://i.sstatic.net/9ZnP7.png
And this is how the collapsed item remains visible momentarily after closing the navbarhttps://i.sstatic.net/zDJoz.png
To display the collapsed navbar across the entire page and change the color upon collapsing, I have used JavaScript in conjunction with CSS. Here is the JavaScript code:
$(".navbar-toggler").click(function(){
$("nav").toggleClass("navbar-blue");
})
And the corresponding CSS code:
.navbar-collapse {
height: 100vh;
}
.navbar{
color: white;
}
.navbar-blue{
background-color: #23415C !important;
}
If anyone can spot the issue in my code, please let me know. I suspect it may be related to the increased size of the collapsing navbar.