I recently set up a navbar for my website, but I'm struggling to grasp the concept of positioning items with Bootstrap. One issue I encountered is that when I click on the dropdown button (profile image), it causes all the items in my navbar to shift, which is something I'd like to avoid:
Check out the code here
HTML :
<div class="pos-f-t">
<nav class="navbar fixed-top navbar-custom" style="height: 80px;">
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">
<img src="assets/img/logo.png" alt="LOGO" style="height: 50px"> Title
</a>
<form class="mx-2 my-auto d-inline w-50">
<input class="form-control mr-sm-6" type="search" placeholder="Search..." aria-label="Search" id="searchBar">
</form>
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<img src="https://mdbootstrap.com/img/Photos/Avatars/avatar-2.jpg" class="rounded-circle z-depth-0"
alt="avatar image" style="height: 50px; outline-width: 10px; outline-color: white">
</a>
<div class="dropdown-menu"
aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">My account</a>
<a class="dropdown-item" href="#">Disconnect</a>
</div>
</li>
</ul>
</nav>
</div>
CSS :
.navbar-custom {
background-color: #2c3e50;
color: white;
font-weight: bold;
font-variant-caps: small-caps;
}
.navbar-toggler-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255,255,255, 1)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}
.navbar-toggler-icon:hover {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255,176,43, 1)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}
.navbar-brand {
margin-left: 2%;
font-size: 30px;
color: white
}
.navbar-brand:hover {
color: #ffb02b;
}
#searchBar {
border-radius: 20px;
font-family:Arial, 'Font Awesome 5 Free'
}
#searchBar:focus {
border-color: #ffb02b;
border-width: 2px;
}