I have the problem that in bootstrap if I put an image into an <a class="navbar-brand"> it messes everything up.
<!-- Nav -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<a class="navbar-brand" href="#">
<img src="img/bee-1000sqr.png" class="bnav-bee" style="padding-right: -100px;" />
Bienenkamera
</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 mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<form action="http://www.lugy-online.de/" method="get">
<button class="btn btn-primary my-2 my-sm-0" type="submit">Zurück zum LuGy</button>
</form>
</div>
</nav>
<!-- /Nav -->
The inside the <a class="navbar-brand"> causes the problem that the navbar-brand <a>-Tag is way to wide and my buttons are far too right and if I size the browser windows down the navbar-toggler is below the navbar-brand.
Can you help me?
.bnav-bee {
max-width: 4%;
margin-top: -10px;
}
I already tried to fix it with width-style(css) in the <a>-Tag and I tried to mess with the padding or margin. Neither of these worked.
Specify the width and the height of your image like in the example below.
And for spacing use the native Bootstrap padding and margin classes such as px-* or pl-* or mx-* etc.
Here's the code snippet:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Nav -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<a class="navbar-brand" href="#">
<img src="https://placehold.it/60" width="30" height="30" class="bnav-bee">
Bienenkamera
</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 mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<form action="http://www.lugy-online.de/" method="get">
<button class="btn btn-primary my-2 my-sm-0" type="submit">Zurück zum LuGy</button>
</form>
</div>
</nav>
<!-- /Nav -->
<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>
Related
I am presently practising some stuff in expressJS and EJS rendering. I noticed that Bootstrap float-right class is not working on the navbar. I even tried d-flex but the result still remain the same. I don't if I am probably doing something wrong. Below is my code:
_header.ejs
<header>
<nav class="navbar navbar-expand-md navbar-dark bg-success">
<a class="navbar-brand" href="/urls">TinyApp</a>
<button
class="navbar-toggler"
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>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="/urls">URLs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/urls/new">New URL</a>
</li>
</ul>
<li class="flaot-right">
<button class="btn btn-outline-danger me-2">
Logout
</button>
</li>
</div>
</div>
</nav>
</header>
This is the button I tried to float to the right
<li class="flaot-right">
<button class="btn btn-outline-danger me-2">
Logout
</button>
</li>
Nothing changes.
I think you should put float-right to the button and set the li tag class to standard (bootstrap 4) nav-item class. Additional we set float-right not flaot-right you have a typo ;-)
Second proposition to set button on the right side is set d-flex and flex-row-reverse to li class like this:
<li class="nav-item d-flex flex-row-reverse">
The code is commented in html code snippet below, You can simple switch if you like second proposition, but remember to remove float-right from button ;-) Good Luck!
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<title>Hello, float vs d-flex Bootstrap 4!</title>
</head>
<body>
<header>
<nav class="navbar navbar-expand-md navbar-dark bg-success">
<a class="navbar-brand" href="/urls">TinyApp</a>
<button class="navbar-toggler" 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>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="/urls">URLs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/urls/new">New URL</a>
</li>
</ul>
<!-- <li class="nav-item d-flex flex-row-reverse"> -->
<li class="nav-item">
<button class="btn btn-outline-danger me-2 float-right">
Logout
</button>
</li>
</div>
</div>
</nav>
</header>
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<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.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
</body>
</html>
I want to add notification badge to a nav link, and I have 2 problems:
1) I can't make it be over the image top-left.
2) When the navbar is collapsed, the badge goes all the way to the left:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light fixed-top" >
<div class="container">
<a class="navbar-brand mx-auto" href="#">
Logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-right" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item main-nav">
<a id="chats_link" class="nav-link" href="/group_chats.php" style="margin-right:15px;color:white;">
<img title="Chats" src="/resources/chat_navbar.png" alt="Chats" width="25" height="25" style="z-index:10;">
<span class="badge badge-primary" style="z-index:15;float:left;margin-bottom:-10px;left:5px; top:-10px;position:relative;">9</span>)
</a>
</li>
</ul>
</div>
</div>
</nav>
would this be what you are looking for? (added left: -20px; to the style of the badge, removed some other stuff)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light fixed-top" >
<div class="container">
<a class="navbar-brand mx-auto" href="#">
Logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-right" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="margin-right:15px;color:white;">
<img src="https://images.freeimages.com/images/large-previews/e71/frog-1371919.jpg" alt="image" width="35" height="35" style="z-index:10;">
<span class="badge badge-primary" style="z-index:15;position:relative; left: -40px; top:-10px"">9</span>)
</a>
</li>
</ul>
</div>
</div>
</nav>
My problem is simple, my navbar-toggler is always visible; even when it doesn't need to be there (on a lg size screen).
File
<div class="navbar-header">
Logo
</div>
<button type="button" class="navbar-toggle bg-dark" data-toggle="collapse" data-target="#mainNavBar" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon visible-sm"></span>
</button>
<div class="container-fluid">
You are using outdated and incomplete code for your navbar.
The navbar-expand-* class group is what controls the navbar expansion now in Bootstrap 4.
In the following code snippet the navbar-expand-lg class makes the navbar expand from the large (lg) breakpoint and up (which means the navbar will be collapsed if the screen is smaller than lg):
<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-lg navbar-light bg-light">
<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>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<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" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<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>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
Reference:
https://getbootstrap.com/docs/4.0/components/navbar/
I'm trying to let users get informed to enable javascript for better use of the website to I want the message placed above the navigation bar using bootstrap, but instead, they stack upon one another. Don't mind how I describe this.
I want them to be placed in this manner:
But they stack on top of each other this way:
Using Bootstrap 4, please any ideas?
Here's some section of the code
<html>
...
<body>
<noscript class='bg-danger text-light py-2 text-center d-block fixed-top mb-4' style='z-index: 9999;'>Enable javascript to use App better.</noscript>
<header class='navbar fixed-top navbar-expand-lg navbar-light bg-light'>
<div class='container'>
...
</div>
</header>
...
</body>
</html>
In the code below the div parts:
<div class='bg-danger text-light py-2 text-center mb-0'>Enable javascript to enhance this App.</div>
would need to be replaced with noscript. The div is just for easy testing/visibility.
To make the whole thing work, you move everything into a div with the fixed-top class and then add your noscript line followed by the navbar code.
Then you'll also need to add something like style="margin-top: 120px;" to the main container that would follow the fixed-top div to push the main content down.
Click the "run code snippet" button 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>
<div class="fixed-top">
<div class='bg-danger text-light py-2 text-center mb-0'>Enable javascript to enhance this App.</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<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>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<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" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<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>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</div>
</nav>
</div>
<p style="margin-top: 120px;">first line of text</p>
So apparently the alpha 6 version of bootstrap 4 has gone all flex, which has broken some of the stuff I was using in alpha 5. As per this fiddle , I'm trying to get the flex justification class to put the navigation bar content over on the right, like so:
<ul class="navbar-nav justify-content-end">
Inspecting the elemnt shows that is has the justify-content: flex-end !important; on it, so I would have expected it to work. Why doesn't it?
To right align the .navbar-nav on desktop devices you need to place the .justify-content-end class on its parent:
add .justify-content-end class to #navbarSupportedContent.
If you want to right align the mobile menu on the right side:
.text-right (instead of .justify-content-end) on your .navbar-nav and
.justify-content-end on your .form-inline.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<nav class="navbar navbar-toggleable-sm navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#replaceThisWithYourOwnId" aria-controls="replaceThisWithYourOwnId" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">BrandName</a>
<div class="collapse navbar-collapse justify-content-end" id="replaceThisWithYourOwnId">
<ul class="navbar-nav text-right">
<li class="nav-item active">
<a class="nav-link ">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0 justify-content-end">
<input class="form-control mr-sm-2" type="text" placeholder="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>