I am using bootstrap 4 to make an application, in which i have two navbars and both needs to be fixed at top in which the second navbar needs to hide while scrolling.
Html:
Navbar 1:
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-custom-light">
<div class="container-fluid">
<div class="row w-100">
<div class="col-md-2 col-lg-2 col-sm-4 col-xs-4">
<a class="navbar-brand" href="#">
New Project
</a>
</div>
<div class="col-md-4 col-lg-4 col-sm-6 col-xs-6 d-none d-sm-none d-md-block mt-2">
<h4 class="font-weight-600">
Little description
</h4>
</div>
<div class="col-3"></div>
<div class="col-3 mt-3 d-none d-sm-none d-md-block">
<ul class="navbar-nav pl-5">
<li class="nav-item mr-3">
<a class="nav-link" href="#">
Notification
</a>
</li>
<li class="nav-item font-weight-600 mr-3">
<a class="nav-link text-capitalize" href="#">
Hello Admin
</a>
</li>
<li class="nav-item font-weight-600 mr-3">
<a class="nav-link text-capitalize mr-3" href="#">
Profile
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
search
</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
Navbar 2:
<nav class="navbar fixed-top navbar-expand-md bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="#">Navbar</a>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
Here both the navbar needs to be fixed top for which i have used fixed-top class..
But as of now the navbars are overlapping each other.
You could see in the link https://www.bootply.com/y8EfMpCMc4# where the overlapping happens.
Kindly help me to place a navbar 2 below navbar 1 with position fixed (which also needs to be responsive), in which the navbar 2 alone needs to be in collapsed for small devices and needs to be on right side of navbar 1's navbrand ie.right to New Project.
Use sticky-top on the 1st instead of fixed-top, and make the 2nd navbar static by removing fixed-top.
<nav class="navbar sticky-top navbar-expand-lg navbar-light bg-custom-light"></nav>
<nav class="navbar navbar-expand-md bg-dark navbar-dark"></nav>
Demo: https://www.codeply.com/go/vbF0Sch9xc
Related:
Bootstrap 4 collapsing two navbars into one toggle button
Bootstrap 4 Multiple fixed-top navbars
Related
I have a website that has a <nav> element at the top where it shows main menu links and a number of other things.
For years it worked just fine across all devices ever tested against (even Microsoft) just not on iPhone 13.
<header class="wrapper header">
<nav class="navbar top navbar-top navbar-expand-lg d-print-none navbar-primary bg-primary text-white fixed-top ">
<a class="navbar-brand" href="/?ref=top_brand_logo">MyWebsite</a>
<div class="mobile-navbar-items d-sm-inline-block d-xs-inline-block d-md-none d-lg-none d-xl-none">
<div class="navbar-text">Hello User!</div>
</div>
<button id="menuButton" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#top-navbar" aria-controls="top-navbar" aria-expanded="false" aria-label="Toggle navigation">X</button>
<div class="collapse navbar-collapse" id="top-navbar">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="link1">Link1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="link2">Link2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="link3">Link3</a>
</li>
</ul>
<div class="navbar-text d-sm-none d-xs-none d-md-inline-block d-lg-inline-block d-xl-inline-block">
Hello Mr Lebowski!
</div>
<ul class="navbar-nav right">
<li class="nav-item">
Log out
</li>
</ul>
</div>
</nav>
</header>
I just don't get it. Have they removed support for <header> or <nav> in the latest iOs Safari? Am I doing something wrong?
I am having an issue with my centered logo on bootstrap navbar menu; I put the logo in the center of the navbar; it is working fine on desktop but when I resize the page to a smaller device, the logo, because of the presence of the Hamburger menu button on the right and its relatively pixels used, becomes out of center towards to the left.
How can I make sure that on devices with smaller screens the logo remains centered?
<nav class="navbar navbar-expand-xl navbar-toggleable-md navbar-light bg-white" id="nav1">
<div class="navbar-collapse collapse w-100 order-1 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item home">
<a class="nav-link" href="#">HOME <span class="sr-only">(current)</span> </li>
<li class="nav-item"> <a class="nav-link" href="#">OUR WEDDINGS </li>
</ul>
</div>
<div class="mx-auto order-0 order-xl-2">
<a class="navbar-brand mx-auto" href="/"><img src="Imagine/00 Top Logo 2021.png" alt="Logo 2021" width="275" height="127"></a></div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<li class="nav-item"> <a class="nav-link" href="#">LEGALITIES </li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
Foreword
Before we go into the solution, one thing to note is that if this solution is implemented and the window is not wide enough to fit both the logo and the toggler without overlapping, they will do just that -- overlap.
Solution
1. Styles
You can do that using transform and position: absolute:
.navbar-brand {
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
/* to place the toggler above the logo, in case they overlap */
.navbar-toggler: {
z-index: 10;
}
2. HTML
There are also some issues in the HTML. The big one is missing closing tags for <a class="nav-link">. See this jsfiddle version and check the HTML textarea for where the linter highlights issues. Also, the sr-only class is for screen readers so you want to include it for each link and make sure the text content matches the link itself -- see this answer for a great explanation of that.
Here's a refactored version of the HTML:
<nav class="navbar navbar-expand-xl navbar-toggleable-md navbar-light bg-white" id="nav1">
<div class="navbar-collapse collapse w-100 order-1 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item home">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/">
HOME
<span class="sr-only">Home</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/wedding_sicily_our_weddings.html">
OUR WEDDINGS
<span class="sr-only">Our Weddings</span>
</a>
</li>
</ul>
</div>
<div class="mx-auto order-0 order-xl-2 navbar-brand-container">
<a class="navbar-brand mx-auto" href="/">
<img src="Imagine/00 Top Logo 2021.png" alt="Logo 2021" width="275" height="127">
</a>
</div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/wedding_sicily_legalities.html">
LEGALITIES
<span class="sr-only">Legalities</span>
</a>
</li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
3. Demo
See this jsfiddle demo for the complete working solution.
Hope that helps!
Add position: absolute in .navbar-toggler. See if it helps you:
https://jsfiddle.net/omk9pg58/
I have a navbar in bootstrap that has the links and a logo in the center. The navbar stretches to fit the logo image, I'd rather have the logo overlap the navbar. Here is my code, I actually used a base someone already made yet it still doesn't work.
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="navbar-collapse collapse w-100 dual-collapse2 order-1 order-md-0">
<ul class="navbar-nav ml-auto text-center">
<li class="nav-item active">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
<div class="mx-auto my-2 order-0 order-md-1 position-relative">
<a class="mx-auto" href="#">
<img src="http://placehold.it/120/ccff00" class="rounded-circle" height="120" width="120">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="navbar-collapse collapse w-100 dual-collapse2 order-2 order-md-2">
<ul class="navbar-nav mr-auto text-center">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
CSS
#media (min-width: 992px) {
.navbar {
height:50px;
}
}
Forgive me if this is a simple question, I'm new to bootstrap 4 and wasn't able to find the answer searching online.
I have a nav bar that is laid out in three columns, logo to the left, small menu in the middle and a logout button to the right.
When I get down to the 550px to 767px screen size, instead of dropping a line, it's just squishing everything and running off the page, I've tried turning off every style in the console but nothing is changing. The only way I've gotten it to work is to remove the navbar class from the nav element, but that breaks the page in every other screen size so that's not the answer.
Here is my HTML code, can someone point me in the right direction? the out come I'm looking for is similar to this (logo above the menus)-
Logo
Menu 1 | Menu 2 | Menu 3 | Menu 4 Logout
html:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" href="/">Logo</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav">
<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">
Name
</a>
<div class="dropdown-menu text-center dropdown-logout" aria-labelledby="navbarDropdown">
<form action="" method="post">
<button type="submit" class="btn btn-primary">Logout</button>
</form>
</div>
</li>
<li class="nav-item">
</li>
</ul>
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link btn-ghost-blue" href="/#">Menu 1</a>
</li>
<li class="nav-item">
<a class="nav-link btn-ghost-blue" href="/#">Menu 2</a>
</li>
<li class="nav-item">
<a class="nav-link btn-ghost-blue" href="/#">Menu 3</a>
</li>
<li class="nav-item">
<a class="nav-link btn-ghost-blue" href="/#">Menu 4</a>
</li>
</ul>
</div>
</div>
</nav>
Thank You!
You probably don't want to use bootstrap 4 responsive navbar from documentation since you don't want to collapse your navbar on small screen. So you might design your own responsive navbar.
Like comment suggested, using the grid system to adjust your col-size for different screen sizes. The following code can give you a idea, run it in full screen and resize your window.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<nav class="navbar navbar-light flex-nowrap flex-row">
<div class="container">
<div class="row w-100">
<div class="col-12 col-sm-auto">
Logo
</div>
<div class="col-12 col-sm-auto">
<ul class="nav navbar-nav flex-row">
<li class="nav-item"><a class="nav-link pr-3" href="">Login</a></li>
<li class="nav-item"><a class="nav-link" href="">Sign up</a></li>
</ul>
</div>
</div>
</div>
</nav>
I am trying to create a website header that conforms to the schematic below using Bootstrap 4:
The code I am using to achieve this is as follows (extraneous code omitted):
<div class="navbar">
<div class="container yellow">
<div class="row">
<div class="col-sm-4 green">Logo</div>
<div class="col-sm-8 green">
<div class="row">
<div class="col text-right red">
(00) 1234 5678
</div>
</div>
<div class="row">
<div class="col text-right red">
<!-- nav links here -->
link
</div>
</div>
</div>
</div>
</div>
</div>
The only custom CSS is to change the background colours to match those of the schematic.
This results in the following rendered HTML page, where the row does not span the container:
However, in Bootstrap 3 this is not an issue. Only changing the framework to Bootstrap 3 gives the correct layout:
Also, the correct layout can be achieved within Bootstrap 4 if the container (and its nested content) is removed from its navbar parent:
What do I need to do within Bootstrap 4 to achieve this desired layout whilst still using the navbar class?
The Bootstrap 4 grid row>col-* aren't designed to be used inside the Navbar. Here is the supported content. Now that Bootstrap 4 uses flexbox, it's much easier to align Navbar content without using the grid row>col-*.
If you want a Navbar with logo and 2 rows, see this answer: https://stackoverflow.com/questions/42635126/bootstrap-4-navbar-with-2-rows
<nav class="navbar navbar-expand navbar-dark fixed-top bg-dark">
<div class="container">
<h1 class="mb-0">Logo</h1>
<div class="d-flex flex-column flex-wrap" id="navbarCollapse">
<span class="navbar-text ml-auto py-0 px-lg-2">(00) 1234 5678</span>
<ul class="navbar-nav mb-auto mt-0 ml-auto">
<li class="nav-item active">
<a class="nav-link py-0" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="#">Product</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="#">Company</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="#">Blog</a>
</li>
</ul>
</div>
</div>
</nav>
Examples:
Basic Navbar with 2 rows: https://codeply.com/go/ilJBKjJsEy
Responsive Navbar with 2 rows: https://codeply.com/go/DsfePuoZy0
The 2nd example collapses into a mobile stacked menu on small screens that can be toggled using the hamburger icon. Use the flexbox and spacing utility classes to position elements as desired. There are many ways to achieve what you want: https://www.codeply.com/go/pGE8fTf9dM
You can use 2 navbar-nav elements and then stack them up by using the flex-column class like so:
<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>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">
<img src="https://picsum.photos/140/70" width="140" height="70" alt="Logo">
</a>
<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 flex-column align-items-end" id="navbarCollapse">
<!-- navbar1 -->
<div class="navbar-nav mb-lg-0">
<a class="nav-item nav-link" href="#">(00) 1234567</a>
</div>
<!-- navbar2 -->
<ul class="navbar-nav mt-0">
<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="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</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">Products</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" href="#">Free Cookies</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>