I have a navbar for bootstrap 4 and the nav-brand centered on computer window, but it will moving to dropdown when expand the toggle on mobile. Does there any way to make the brand fixed on top and center?
my navbar code on html:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown"
aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-start" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-
toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i
class="fas fa-store mr-3"></i>Product
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="...">..</a>
</div>
</li>
<li class="nav-item active">
<a class="nav-link" href="/" style="color: papayawhip"><i class="fas fa-home mr-3"></i>Home
<span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
<a class="navbar-brand mx-auto" href="/"><img src="....." style="max-height: 60px" /></a>
<div class="collapse navbar-collapse justify-content-end" id="navbarNavDropdown">
<ul class="navbar-nav"><li class="nav-item">
<a>...</a>
</li>
</ul>
</div>
</nav>
try doing this so the navbar-brand
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
so the navbar-brand is outside the navbarNavDropdown
Related
The dropdown for User is cuf of, I'm using Bootstrap 5. I read an older article here on stackoverflow that recommended putting .dropdown-menu-left/.dropdown-menu-right on the </ul> which didn't work for me.
I think what would work if I somehow could bring my dropdown to appear to the bottom left of my User link. Blow I attached the source code, probably a little bit to much, but maybe you need to see the entire nav.
See dropdown menu cutting of to the right.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-lg">
<a class="navbar-brand" href="{{ url_for('index') }}">
<img src="../static/logo.png" alt="" width="30" height="24" class="d-inline-block align-text-top">
Homepage
</a>
<button class="navbar-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 me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" href="/blog">Blog</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown"
aria-expanded="false">Username
</a>
<ul class="dropdown-menu" aria-labelledby="userDropdown">
<li><a class="dropdown-item" href="/logout">Log Out</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
left and right have changed to start and end in Bootstrap 5. Therefore..
dropdown-menu-right is now dropdown-menu-end
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-lg">
<a class="navbar-brand" href="{{ url_for('index') }}">
<img src="../static/logo.png" alt="" width="30" height="24" class="d-inline-block align-text-top">
Homepage
</a>
<button class="navbar-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 me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" href="/blog">Blog</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown"
aria-expanded="false">Username
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
<li><a class="dropdown-item" href="/logout">Log Out</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
Demo
I have a menu. When I click on the anchor link, page floats to the left about 50 pixels.
When I delete div which wrapped nav it don't helps.
What can I do?
Shifting effect
<div class="sticky-top container-fluid p-0">
<nav class="navbar navbar-expand-lg navbar-light bg-light" >
<a class="navbar-brand px-3" href="#"><img src="img/logo_0.png" style="height: 2.5em" alt=""></a>
<button class="me-3 navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon "></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mx-3 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="#ac">One</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/pages/service.html">Two</a>
</li>
</ul>
</div>
</nav>
</div>
I want to have the nav-bar such that the name of the company is on the left with items X and Y on the right. I tried using justify-content-right as suggested in bootstrap documentation but it doesn't work.
<header>
<nav class="navbar navbar-expand-md fixed-top whitelight nav-masthead">
<a class="navbar-brand gold-text font-weight-bold" href="index.php">Company Name</a>
<!--Creates a clickable button with a toggle icon once the screen collapses-->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-flex flex-row" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link text-black" style="font-size:16px; href="x.php">X <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link text-black" style="font-size:16px; href="y.php">Y<a>
</li>
</ul>
</div>
</nav>
<header>
Edit: I removed mr-auto class and that seemed to do the trick!
You forgot to close style attribute
<header>
<nav class="navbar navbar-expand-md fixed-top whitelight nav-masthead">
<a class="navbar-brand gold-text font-weight-bold" href="index.php">Company Name</a>
<!--Creates a clickable button with a toggle icon once the screen collapses-->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-flex flex-row" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link text-black" style="font-size:16px"; href="x.php">X <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link text-black" style="font-size:16px"; href="y.php">Y<a>
</li>
</ul>
</div>
</nav>
<header>
I'm trying to get my nav menu to collapse on mobile devices, but not on desktops.
Adding data-toggle="collapse" data-target="#navbarResponsive" seems to work, but then nav items also collapse when they're clicked on a desktop device.
<div class="py-0 px-3 fixed-top">
<nav class="navbar container navbar-transparent navbar-padded navbar-expand-md">
<a class="navbar-brand" href="#">
Logo
</a>
<button
class="navbar-toggler navbar-toggler-right d-md-none"
type="button"
data-toggle="collapse"
data-target="#navbarResponsive"
aria-controls="navbarResponsive"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-uppercase" id="navbarResponsive">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item" data-toggle="collapse" data-target="#navbarResponsive">
<a class="nav-link"href="#link1">link1</a>
</li>
<li class="nav-item" data-toggle="collapse" data-target="#navbarResponsive">
<a class="nav-link" href="#link2">link2</a>
</li>
</ul>
</div>
</nav>
</div>
Change the data-target to the mobile collapsed version: .navbar-collapse.show
<li class="nav-item" data-toggle="collapse" data-target=".navbar-collapse.show">
<a class="nav-link" href="#link1">link1</a>
</li>
Demo: https://www.codeply.com/go/qBh0qJYekK
Related: How to hide collapsible Bootstrap 4 navbar on click
This question already has answers here:
Bootstrap align navbar items to the right
(24 answers)
Closed 5 years ago.
I'm trying to align my navbar items to the right in bootstrap 4 alpha 6.
I'd like to have everything aligned right, except for the brand/title.
This is what my code looks like:
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Oliver</a>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">About <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#projects">Projects</a>
<a class="nav-item nav-link" href="#contact">Contact</a>
</div>
</div>
</nav>
You can add .justify-content-end to the .navbar-collapse element. And I'm assuming you also want to move the mobile toggle menu items to the right. To do that, add .align-items-end to .navbar-nav
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Oliver</a>
<div class="collapse navbar-collapse justify-content-end" id="navbarNavAltMarkup">
<div class="navbar-nav align-items-end">
<a class="nav-item nav-link active" href="#">About <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#projects">Projects</a>
<a class="nav-item nav-link" href="#contact">Contact</a>
</div>
</div>
</nav>