Dropdown menu is out of the screen - html

I want to add a dropdown menu to my navbar but the menu is always out of the page.
Here is my code :
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">PEL</a>
<div class="btn-group">
<button
type="button"
class="btn btn-secondary dropdown-toggle mr-3"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">${pseudo}</button>
<div class="dropdown-menu dropdown-menu-right">
<button
class="dropdown-item dropdown-menu-right"
type="button">Action</button>
<button
class="dropdown-item dropdown-menu-right"
type="button">Another action</button>
<button
class="dropdown-item dropdown-menu-right"
type="button">Something else here</button>
</div>
</div>
</nav>
Dropdown works good but it is always out of the right side of my screen...
A little space is created by my dropdown menu on the right side of the page.

According to the v4.0 doc :
https://getbootstrap.com/docs/4.0/components/dropdowns/#menu-alignment
Heads up! Dropdowns are positioned thanks to Popper.js (except when they are contained in a navbar).
Two options :
Upgrade your bootstrap version. It's working fine with v4.6
Use custom classes instead of bootstrap navbar
[EDIT 1] Here is a working example with bootstrap v4.6. Also i have removed the mr-3 class for better rendering.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">PEL</a>
<div class="btn-group">
<button
type="button"
class="btn btn-secondary dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">${pseudo}</button>
<div class="dropdown-menu dropdown-menu-right">
<button
class="dropdown-item"
type="button">Action</button>
<button
class="dropdown-item"
type="button">Another action</button>
<button
class="dropdown-item"
type="button">Something else here</button>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/jquery#3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>

Related

Bootstrap 5 navbar menu in sidebar not working

I am facing an issue when trying to create a responsive menu or dropdown button with Bootstrap 5. Everything seems ok. The navigation icon & dropdown icon appear. But it's not working. When I clicked the nav icon or dropdown button, no dropdown menu appeared.
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- link rel="stylesheet" href="css/bootstrap.rtl.min.css" -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<title>Test</title>
</head>
<body>
<nav class="navbar navbar-light bg-light navbar-expand-sm mb-3">
<a class="navbar-brand">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" tabindex="0" data-bs-toggle="dropdown" data-bs-submenu="" aria-expanded="false">Dropdown 3</a>
<div class="dropdown-menu dropdown-menu-right">
<div class="dropdown dropend dropdown-submenu">
<button class="dropdown-item dropdown-toggle" type="button" data-bs-toggle="dropdown">Action</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button">Sub action</button>
<div class="dropdown dropend dropdown-submenu">
<button class="dropdown-item dropdown-toggle" type="button">Another sub action</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button">Sub action</button>
<button class="dropdown-item" type="button">Another sub action</button>
<button class="dropdown-item" type="button">Something else here</button>
</div>
</div>
<button class="dropdown-item" type="button">Something else here</button>
<button class="dropdown-item" type="button" disabled="">Disabled action</button>
<div class="dropdown dropend dropdown-submenu">
<button class="dropdown-item dropdown-toggle" type="button">Another action</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button">Sub action</button>
<button class="dropdown-item" type="button">Another sub action</button>
<button class="dropdown-item" type="button">Something else here</button>
</div>
</div>
</div>
</div>
<div class="dropdown-header">Dropdown header</div>
<div class="dropdown dropend dropdown-submenu">
<button class="dropdown-item dropdown-toggle" type="button">Another action</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button">Sub action</button>
<button class="dropdown-item" type="button">Another sub action</button>
<button class="dropdown-item" type="button">Something else here</button>
</div>
</div>
<button class="dropdown-item" type="button">Something else here</button>
<div class="dropdown-divider"></div>
<button class="dropdown-item" type="button">Separated link</button>
</div>
</li>
</ul>
</div>
</nav>
<!-- script src="js/bootstrap.bundle.min.js"></script -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
</body>

how i can have a container in dropdown navbar?

I want to create a navbar like this site: digikala.com
my problem is when the mouse goes on menu item drop-down on mouse hover and open a container for all links to show in right
I want to know how I can have a container like this site?
I use bootstrap 4.6 in this page
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" style="color: purple;" href="#">Partineh</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">
<div class="dropdown">
<button class="btn" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<h5>دسته بندی کالاها</h5>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<div class="menu-grid">
<div class="btn-group dropleft">
<button type="button" class="btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropleft
</button>
<div class="dropdown-menu">
<!-- Dropdown menu links -->
<button class="dropdown-item" type="button">Action</button>
<button class="dropdown-item" type="button">Another action</button>
<button class="dropdown-item" type="button">Something else here</button>
</div>
</div>
<div class="btn-group dropleft">
<button type="button" class="btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropleft1
</button>
<div class="dropdown-menu">
<!-- Dropdown menu links -->
<div class="container">
<div class="row">
<div class="col-12">
<button class="dropdown-item" type="button">Action1</button>
<button class="dropdown-item" type="button">Another action1</button>
<button class="dropdown-item" type="button">Something else here1</button>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">سوپرمارکت</a>
</li>
</ul>
</div>
</nav>

Navbar dosen't open

Hi I am trying to make a navbar but my dropdown menu dosen't work. Can someone help me with this? Also I want to ask how can I put multiple colors in a navbar?
<!DOCTYPE html>
<html>
<head>
<title>Tesla</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style type="text/css"></style>
</head>
<body>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="file:///C:/Users/User/Desktop/navbar.html">Tesla</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>
<a class="nav-link dropdown-toggle" href="" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</nav>
</body>
</html>
You need to have Javascript in place that will decide what happens when the user clicks on the dropdown icon.
I would recommend having a look at this example:
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_mobile_navbar

Bootstrap's v4 btn-outline-primary doesn't work

Bootstrap's v4 btn-outline-primary doesn't work on the nav links when viewed on my iPhone, but works fine (albeit solid without outline) when viewed on my laptop and desktop screens. I looked around and didn't find any solutions specific to this. I'm using Bootstrap 4.0.0.
HTML is:
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
</head>
<body>
<!-- START NAVBAR -->
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<div class="container">
<!-- ADDED DIV TO MANIPULATE POSITIONS OF "navbar-brand" and "navbar-nav", the ul -->
<span class="navbar-brand mb-0 h1">JavaScript Is Cool</span>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<!-- removed .active -->
<a class="nav-link btn-outline-primary" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link btn-outline-primary" href="/bio">Bio</a>
</li>
<li class="nav-item">
<a class="nav-link btn-outline-primary" href="/history">Resume´</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle btn-outline-primary" href="" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Coming Soon</a>
<a class="dropdown-item" href="#">Coming Soon</a>
<a class="dropdown-item" href="#">Coming Soon</a>
</div>
</li>
</ul>
<!-- REMOVED THE SEARCH FORM -->
<!-- <form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form> -->
</div>
</div>
<!-- END ADDED DIV -->
</nav>
<!-- END NAVBAR -->
<!-- START JUMBOTRON -->
<div class="jumbotron jumbotron-fluid">
<div class="container">
<div class="row">
<div class="col titleDiv">
<h1 class="line1">RON SMITH</h1>
<p class="line2">JavaScript Is Cool</p>
</div>
</div>
</div>
</div>
<!-- END JUMBOTRON -->
<!-- START FOOTER -->
{{>footer}}
<!-- END FOOTER -->
<script src="../js/jquery.slim.min.js"></script>
<script src="../js/popper.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
</body>
Everything works fine except when tapping on iPhone. There's no highlighting of the button or links with color in responsive mode.
The btn-outline-primary class is not designed to be used the way you were using it. So, saying that it "works fine" means you misunderstood how it was supposed to work in the first place because based on the current behavior resulting from your code, it does NOT work "fine".
To make the btn-outline-primary class work the way it's supposed to be used and work, you need to add the btn class additionally to that as shown in the code snippet below. In other words, btn is required for btn-outline-primary to work properly even though the effect you get that way might not be the effect you were going for.
Here's the code snippet (click "run code snippet" below and expand to full page):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<div class="container"> <!-- ADDED DIV TO MANIPULATE POSITIONS OF "navbar-brand" and "navbar-nav", the ul -->
<span class="navbar-brand mb-0 h1">JavaScript Is Cool</span>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item"> <!-- removed .active -->
<a class="nav-link btn btn-outline-primary" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link btn btn-outline-primary" href="/bio">Bio</a>
</li>
<li class="nav-item">
<a class="nav-link btn btn-outline-primary" href="/history">Resume´</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link btn dropdown-toggle btn-outline-primary" href="" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Coming Soon</a>
<a class="dropdown-item" href="#">Coming Soon</a>
<a class="dropdown-item" href="#">Coming Soon</a>
</div>
</li>
</ul>
<!-- REMOVED THE SEARCH FORM -->
<!-- <form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form> -->
</div>
</div> <!-- END ADDED DIV -->
</nav>

Dropdown react doesn't work with Bootstrap v4

I have a table and in last column I have the following drop down:
<td>
<div>
<button aria-expanded="false" aria-haspopup="true" data-toggle="dropdown" id="dropdownMenu2" type="button">Dropdown</button>
<div aria-labelledby="dropdownMenu2">
<button type="button">Action</button> <button type="button">Another action</button> <button type="button">Something else here</button>
</div>
</div>
</td>
When I click on drop down it doesn't open, what could the problem be?
Could it caused by the aria and data attributes?
I don't think the className attributes are working here. If you replace "className" by "class" and just add bootstrap it works.
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
</head>
<body>
<td>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<button class="dropdown-item" type="button">Action</button>
<button class="dropdown-item" type="button">Another action</button>
<button class="dropdown-item" type="button">Something else here</button>
</div>
</div>
</td>
</body>
</html>
I had a similar issue. After moving the script files (bootstrap, jquery, etc) from bottom of the file into the <head> bootstrap dropdowns started working.