Half of the dropdown is hidden [duplicate] - html

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

Related

Why my navbar toggler button from bootstrap don't show the list of nav items?

I have this code in html and i want to show de nav items when the navbar collapse, because is not showing anything when a press the toogler button.
<div class="container-fluid ">
<a class="navbar-brand nav-color">
> $ / kromabyte /~
</a>
<span class="logo__cursor"></span>
<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 justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link nav-color " aria-current="page" href="#">index /</a>
</li>
<li class="nav-item">
<a class="nav-link nav-color" href="#about">About /</a>
</li>
<li class="nav-item">
<a class="nav-link nav-color" href="#">Portfolio /</a>
</li>
<li class="nav-item">
<a class="nav-link nav-color">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
You can try to change these props for the toggler button:
data-bs-toggle="collapse" to data-toggle="collapse"
data-bs-target="#navbarNav" to data-target="#navbarNav"
Hope this can help.

Bootstrap navigation button isn't working on mobile version

I tried to make an responsive bootstrap navigation bar but something isn't working. I even copy/paste the bootstrap navbar example and still the button doesn't show the menu when I click on it.
Can you help me solve it ?
<div class="header">
<nav class="navbar navbar-expand-lg cust">
<div class="container">
<a class="navbar-brand pSize" href="#">
<img src="log.png" class="d-inline-block imgBrandSize">
Logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<i class="fa-solid fa-bars fa-lg"></i>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
<div class="header">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand pSize" href="#">
<img src="log.png" class="d-inline-block imgBrandSize">
Logo
</a>
<button class="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 ms-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
this is working properly. This is Bootstrap-5. Please use data-bs-toggle and data-bs-target insted of data-toggle and data-target
Please Check This Code
I hed Two changes in your code.
This Is Bootstrap v4.0.0
<div class="header">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand pSize" href="#">
<img src="log.png" class="d-inline-block imgBrandSize">
Logo
</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>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Text</a>
</li>
</ul>
</div>
</div>
</nav>
enter image description here

How to align navbar items right in Bootstrap 5

I know there are already a lot of questions asked about how to do this, but I am not understanding where exactly should I place the class in my code. I am using Bootstrap 5.1.3.
Also, could someone identify if I am doing/including any "extra stuff" that is redundant or I can remove.
My Code:
<nav class="navbar navbar-light bg-light fixed-top navbar-expand-md mr-auto">
<div class="container-fluid">
<div class="navbar-brand">
Shubham Salunke
</div>
<button class="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 me-auto mb-2 mb-lg-0">
<li class="nav-item"> <a class="nav-link" href="#home"> Home </a> </li>
<li class="nav-item"> <a class="nav-link" href="#about"> About </a> </li>
<li class="nav-item"> <a class="nav-link" href="#projects"> Works </a> </li>
<li class="nav-item"> <a class="nav-link" href="#social"> Social Media </a> </li>
</ul>
</div>
</div>
</nav>

Cannot align to right margin with bootstrap

I read a lot of post about this issue but I still cannot align my button to the right margin.
I have a navbar with multiple buttons and I need to align to the right the SingIn/SignOut button.
This is my code:
<header th:fragment="header">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Spring Boot</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-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 active"><a class="nav-link" href="#">Home
<span class="sr-only">(current)</span>
</a></li>
<li class="nav-item"><a class="nav-link" th:href="#{/listar}">Clientes</a>
</li>
</ul>
<ul class="navbar-nav mr-auto">
<li sec:authorize="!isAuthenticated()"><a
class="btn btn-outline-primary" th:href="#{/login}">Sign In</a></li>
<li sec:authorize="isAuthenticated()" class="dropdown show">
<a class="btn btn-outline-primary dropdown-toggle" href="#"
role="button" id="dropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false"><span sec:authentication="name"></span></a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<form id="logoutForm" th:action="#{/logout}" method="post">
<button class="dropdown-item" onclick="document.getElementById('logoutForm').submit();" type="submit">Sign Out</button>
</form>
</div>
</li>
</ul>
</div>
</nav>
Change your mr-auto for ml-auto in:
<ul class="navbar-nav mr-auto"> because the way you set it push the block to the left by adding a margin-right: auto;
<header th:fragment="header">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Spring Boot</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-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 mr-auto"> <!-- add the mr-auto class here -->
<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" th:href="#{/listar}">Clientes</a>
</li>
</ul>
<ul class="navbar-nav"> <!-- remove the mr-auto class here -->
<li sec:authorize="!isAuthenticated()"><a
class="btn btn-outline-primary" th:href="#{/login}">Sign In</a></li>
<li sec:authorize="isAuthenticated()" class="dropdown show">
<a class="btn btn-outline-primary dropdown-toggle" href="#"
role="button" id="dropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false"><span sec:authentication="name"></span></a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<form id="logoutForm" th:action="#{/logout}" method="post">
<button class="dropdown-item" onclick="document.getElementById('logoutForm').submit();" type="submit">Sign Out</button>
</form>
</div>
</li>
</ul>
</div>
</nav>
See https://getbootstrap.com/docs/4.5/components/navbar/ for more info.
The mr-auto class was in the wrong place. It sets margin right to auto, which you should have on the parent component, not on the child

(asp.net) Bootstrap 4 Navbar toggler not working

I'm using bootstrap 4 in asp.net (.net framework). When I change the website view to mobile view from pc view, the navbar-toggler-icon button is working. The navbar content is not showing when I press the toggler-icon button. the navbar-collapse id is same with the data-target, but it's still not working, Can you help me please.
Here is my code:
<nav id="navbar" class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="/index.aspx">
<img class="logo" src="img/Logo/logo_Rueston.png" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="navbar-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" id="navbarCollapse">
<ul class="navbar-nav navbar-center ml-auto">
<li class="nav-item ml-3">
<a class="nav-link" href="/index.aspx">Home<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item ml-3">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item ml-3">
<a class="nav-link" href="#">Products</a>
</li>
<li class="nav-item ml-3">
<a class="nav-link" href="#">Rueston Water</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item ml-3">
<a class="nav-link" href="#">
<asp:Label ID="lbLogin" runat="server" Text="Login"></asp:Label>
</a>
</li>
<li class="nav-item ml-3">
<a class="nav-link" href="#">
<asp:Label ID="lbSignup" runat="server" Text="SignUp"></asp:Label>
</a>
</li>
</ul>
</div>
</div>
</nav>
Here is the demo picture:
before pressing the toggler button:
After pressing the toggler button
Change data-toggle="navbar-collapse" in the button to data-toggle="collapse"
<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>