I have a page with a Boostrap navbar. When we scale the page down, all of the navbar items collapse to the burger menu. Now, as expected, when we roll out the burger menu, the items are displayed in a "Burger" pattern, basically one under another. What I want to achieve is, to make the items, not displayed one under another, but one next to each other.
Visually Explained
Does anyone know how to do this?
(I am using the normal navbar presets, from the boostrap website:)
Here is the code that I want to transform:
<nav id="mynavbar" class="navbar navbar-expand-lg navbar-dark sticky-top">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img
id="Logo"
src="https://cdn.glitch.global/123df645-7c49-4cd3-b292-825ade4e767b/LogoTrimmedNewFont.png?v=1688645785034"
/>
</a>
<button
class="navbar-toggler custom-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-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">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">
<i class="bi bi-person-vcard"></i>
</a>
<h5 class="tooltiptext" style="text-align: left">
Portfolio
</h5>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="bi bi-person-check"></i>
</a>
<h5 class="tooltiptext" style="text-align:">
Hiring
</h5>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="bi bi-diagram-3"></i>
</a>
<h5 class="tooltiptext" style="text-align: left">
Links
</h5>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="bi bi-envelope"></i>
</a>
<h5 class="tooltiptext" style="text-align:">
Contact
</h5>
</li>
</ul>
</div>
</div>
</nav>
I have already tried to set:
@media (max-width:768px){
.navbar-nav{
display: inline;
}
.navbar-nav li{
display: inline;
}
}
but with no success…
2
Answers
You can set
.navbar-nav
todisplay: flex
andflex-direction: row
. Then add some padding/margins to.navbar-nav li
JS Fiddle example: https://jsfiddle.net/vzeLwt62/
You can give flex-direction: row to the .navbar-nav class.
But note that, due to css specificity, select the class with the element ul, otherwise bootstrap default css will override your flex-direction value.
Here is an example snippet:-
The snippet used is from the boostrap website.