I am trying to add a full-width nav bar with Bootstrap 4 and have the left and right most links touch the edge of the container (see the nav on Etsy.com for an example of what I'm trying to achieve):
I've tried to use text-left on each nav link, but the right-most link isn't aligned properly.
Here is the CodePly I'm using:
https://www.codeply.com/go/I9X4D7HpZ2
How do I get the nav to be full width, with the left and right most links touching the edges?
Thanks
Current Code:
<nav class="navbar navbar-expand-sm navbar-light pl-2 pt-0 pb-2 border-bottom">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav nav-fill w-100">
<li class="nav-item">
<a class="nav-link text-dark mr-4 text-left" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark mr-4 text-left" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark mr-4 text-left" href="#">Link 3</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark mr-4 text-left" href="#">Link 4</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark mr-4 text-left" href="#">Link 5</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark text-left" href="#">Link 6</a>
</li>
</ul>
</div>
</nav>
You have to override default bootstrap styles and there are also some classes that are causing some problems (like text-left). Try this:
<div class="container">
<header>
<div>
<nav class="navbar navbar-expand-sm navbar-light bg-white flex-row">
<a class="navbar-brand mr-auto" href="/"><span style="color:#0099ff">MyBrand</span></a>
<form class="form-inline my-2 my-lg-0">
<input class="form-control form-control-sm mr-sm-2" type="text" placeholder="Search">
<button class="btn btn-sm btn-outline-secondary my-2 my-sm-0" type="submit">Search</button>
</form>
<button class="navbar-toggler ml-lg-0" 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>
</nav>
<nav class="navbar navbar-expand-sm navbar-light pl-2 pt-0 pb-2 border-bottom">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav nav-fill w-100 justify-content-between">
<li class="nav-item flex-grow-0">
<a class="nav-link d-inline-block text-dark text-center" href="#">Link 1</a>
</li>
<li class="nav-item flex-grow-0">
<a class="nav-link d-inline-block text-dark text-center" href="#">Link 2</a>
</li>
<li class="nav-item flex-grow-0">
<a class="nav-link d-inline-block text-dark text-center" href="#">Link 3</a>
</li>
<li class="nav-item flex-grow-0">
<a class="nav-link d-inline-block text-dark text-center" href="#">Link 4</a>
</li>
<li class="nav-item flex-grow-0">
<a class="nav-link d-inline-block text-dark text-center" href="#">Link 5</a>
</li>
<li class="nav-item flex-grow-0">
<a class="nav-link text-dark text-center" href="#">Link 6</a>
</li>
</ul>
</div>
</nav>
</div>
</header>
</div>
Related
I want my navbar to appear as a list after collapsing when User press toggle button but it appears in one line and not as a list
This is how the navbar looks i dont want it
This is how i want it to look
<!-- Navbar -->
<nav class="navbar navbar-light navbar-expand-md bg-dark">
<i class="fas fa-child text-warning fa-2x"></i>
<button type="button" class="navbar-toggler bg-light" data-toggle = "collapse" data-target ="#nav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-between" id="nav">
<ul class="navbar nav">
<li class = "nav-item">
<a class="nav-link text-light font-weight-bold text-uppercase px-3" href="#">Home</a>
</li>
<li class = "nav-item">
<a class="nav-link text-light font-weight-bold text-uppercase px-3" href="#">Skills</a>
</li>
<li class = "nav-item dropdown" data-toggle = "dropdown">
<a class="nav-link text-light font-weight-bold text-uppercase px-3 dropdown-toggle" href="#">Projects</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Project 1</a>
<a class="dropdown-item" href="#">Project 2</a>
<a class="dropdown-item" href="#">Project 3</a>
<a class="dropdown-item" href="#">Project 4</a>
</div>
</li>
<li class = "nav-item">
<a class="nav-link text-light font-weight-bold text-uppercase px-3" href="#">Team</a>
</li>
<li class = "nav-item">
<a class="nav-link text-light font-weight-bold text-uppercase px-3" href="#">Contact</a>
</li>
</ul>
<form class="form-inline">
<div class="input-group">
<input type="text" name="" placeholder="Search" class="form-control">
</div>
<div class="input-group-append">
<button class="btn">
<i class="fas fa-search text-muted "></i>
</button>
</div>
</form>
</div>
</nav>
<!-- End of navbar -->
how about this?
<!-- Navbar -->
<nav class="navbar bg-dark navbar-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-
toggle="collapse" data-target="#collapsibleNavbar" aria-
expanded="true">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse show"
id="collapsibleNavbar" style="">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Link</a>
</li>
<li>
<form class="form-inline">
<div class="input-group">
<input type="text" name="" placeholder="Search"
class="form-control">
</div>
</li>
</ul>
</div>
</nav>
<!-- End of navbar -->
This question already has answers here:
Bootstrap NavBar with left, center or right aligned items
(14 answers)
Center an element in Bootstrap Navbar
(10 answers)
Closed 4 years ago.
I need to achieve the brand logo in left, menu items to be center and couple of buttons in the right. I have tried using the flexbox approach but the center items does not align well. and also the brand logo has a wide space with a clickable link.
JS Fiddle
<nav class="navbar navbar-light navbar-expand-md bg-faded justify-content-center">
<div class="container">
<img src="assets/logo/" alt="logo">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100 ml-auto" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">How it works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Become a tutor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto w-100 justify-content-end">
<li class="nav-item">
<a class="btn btn-link" href="#">Sign In</a>
</li>
<li class="nav-item">
<a class="btn btn-primary" href="#">Sign Up</a>
</li>
</ul>
</div>
</div>
</nav>
Answering my own question few months later.
<nav class="navbar navbar-light navbar-expand-md bg-white justify-content-center main--navigation dark-header">
<a href="#" class="navbar-brand d-flex w-50 mr-auto">
<img src="assets/images/logo-header.svg" class="navigation__logo" alt="Logo" />
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100" id="collapsingNavbar">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">Browse</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">How it works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Become a tutor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Prices</a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto w-100 justify-content-end">
<li class="nav-item dropdown no-arrow mx-1 nav-link px-0">
<button id="bookmarksDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" type="button" class="btn btn-outline-secondary btn-outlined" data-original-title="Bookmarks"><img src="assets/icons/bookmark-header-dark.svg"></button>
<div class="dropdown-list dropdown-menu dropdown-menu-right" aria-labelledby="alertsDropdown">
<h6 class="dropdown-header">
Bookmarks
</h6>
</div>
</li>
<li class="nav-item dropdown no-arrow mx-1 nav-link px-0">
<button id="messagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" type="button" class="btn btn-outline-secondary btn-outlined" data-original-title="Notifications"><img src="assets/icons/bell-header-dark.svg"></button>
<div class="dropdown-list dropdown-menu dropdown-menu-right" aria-labelledby="notificationsDropdown">
<h6 class="dropdown-header">
You do not have any notifications yet
</h6>
</div>
</li>
<li class="nav-item dropdown no-arrow mx-1 ml-3 mr-0 nav-link px-0">
<a class="nav-link dropdown-toggle pr-0" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div class="header__profile__title d-inline-block text-right align-middle">
<span class="mr-2 d-none d-block header__profile__name">Aaron Alexander</span>
<span class="mr-2 d-none d-block header__profile__role">Student</span>
</div>
<div class="header__profile d-inline-block">
<img class="img-profile rounded" src="assets/images/andrew-franklin.jpeg" alt="Aaron Alexander">
</div>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="userDropdown">
<a class="dropdown-item" href="#">
<i class="fas fa-user fa-sm fa-fw mr-2"></i>
Profile
</a>
<a class="dropdown-item" href="#">
<i class="fas fa-cogs fa-sm fa-fw mr-2"></i>
Settings
</a>
<a class="dropdown-item" href="#">
<i class="fas fa-list fa-sm fa-fw mr-2"></i>
Activity Log
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">
<i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
Logout
</a>
</div>
</li>
</ul>
</div>
</nav>
That container div you added after the nav makes you loose the flexbox attributes.
You also set the logo with the class "w-100" which takes all possible width.
I removed those and got a nicely aligned navbar.
<nav class="navbar navbar-light navbar-expand-md bg-faded justify-content-center align-items-center">
<img src="assets/logo/" alt="logo">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100 ml-auto" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">How it works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Become a tutor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto w-100 justify-content-end">
<li class="nav-item">
<a class="btn btn-link" href="#">Sign In</a>
</li>
<li class="nav-item">
<a class="btn btn-primary" href="#">Sign Up</a>
</li>
</ul>
</div>
</nav>
Here's a fiddle with the results.
here is my working example.
You just need to put all content into single div in order to Justify content with bootstrap classes. Also, I am using navbar-brand and making them show hide depending on screen resolution. You can do that with js which might be smoother once the page loads completely.
#media only screen and (max-width: 991px) {
.logo {
display: flex;
}
.collapse .navbar-brand {
display: none
}
}
#media only screen and (min-width: 992px) {
.logo {
display: none;
}
.collapse .navbar-brand {
display: none;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light d-flex ">
<a class="navbar-brand logo" 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 justify-content-between" id="navbarSupportedContent">
<a class="navbar-brand" href="#">Navbar</a>
<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" 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>
I am trying to create a basic anchor link within the same page. I am using Bootstrap 4 (whether that makes a difference or not). The link and the target are both in server-side includes. I want to link from the upper nav "Contact" to the form I have in the footer.
In the "upperNav" include I have the following:
<a class="nav-link text-light main-menu" href="#contactMe">Contact</a>
In the "footer" include I have the following:
<p class="contactUs"><a id="#contactMe">Contact Us</a></p>
But for some reason it doesn't work. I have researched this problem but to no avail. Any suggestions?
<!-- From: https://www.jquery-az.com/bootstrap4/demo2.php?ex=91.0_8 -->
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-info ">
<a class="navbar-brand text-light logo-text" href="http://shamar.org/" >shamar.org</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#demo-navbar" aria-controls="demo-navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="demo-navbar">
<ul class="navbar-nav mr-auto" id="menu">
<li class="nav-item">
<a class="nav-link text-light main-menu" href="/index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-light main-menu" href="/articles/index.html">Articles</a>
</li>
</li>
<li class="nav-item">
<a class="nav-link text-light main-menu" href="/weblog/">Blog</a>
</li>
</li>
<li class="nav-item">
<a class="nav-link text-light main-menu" href="/books.html">Books</a>
</li>
</li>
<li class="nav-item">
<a class="nav-link text-light main-menu" href="/multimedia/index.html">Multimedia</a>
</li>
</li>
<li class="nav-item">
<a class="nav-link text-light main-menu" href="/about.html">About</a>
</li>
</li>
<li class="nav-item">
<a class="nav-link text-light main-menu" href="#contactMe">Contact</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-light submit2 my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
Change
<a id="#contactMe">Contact Us</a>
To
<a id="contactMe">Contact Us</a>
experts,
I am trying to upgrade to bootstrap 4, and I am having a hard time with the flex containers.
For some reason, my navbar menu links both submenu and mainmenu are not aligned right. However, when I remove the submenu ul content completely the main menu correctly aligns to the right.
what am I missing here?
thanks in advance.
https://codepen.io/orthix/pen/ZobjMa
<nav class="header navbar navbar-expand-md navbar-light fixed-top bg-light">
<div class="container">
<div class="navbar-brand">
Logo
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarMenu" aria-controls="navbarMenu" aria-expanded="false" aria-label="Toggle navigation">
Menu
</button>
<div class="collapse navbar-collapse flex-column align-items-end" id="navbarMenu">
<div class="row">
<ul class="col-12 navbar-nav navbar-submenu ml-auto order-last">
<li class="nav-item">
<a class="nav-item nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-item nav-link" href="#">Link</a>
</li>
</ul>
<ul class="col-12 navbar-nav ml-auto order-xs-first order-md-last">
<li class="nav-item active">
<a class="nav-link" href="#">Home</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>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link btn btn-sm btn-outline-secondary" href="#">button 1</a>
</li>
<li class="nav-item">
<a class="nav-link btn btn-sm btn-danger text-white" href="#">button 2</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
You need to use justify-content-end utility class.
Here is working codepen: https://codepen.io/anon/pen/rvOZBK
Read more about flexbox utility classes for justifying content here: https://getbootstrap.com/docs/4.1/utilities/flex/#justify-content
I'm currently using the example from bootstrap called 'dashboard' I'm wanting to get the top navbar to actually tuck underneath the side navbar. Like this example: Image Example from Dribbble
I've put the dashboard code from bootstrap onto jsfiddle for ease of use for those that are willing to help (I really appreciate any help with this).
https://jsfiddle.net/1dy65wqx/
It should impact this:
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Dashboard</a>
<button class="navbar-toggler d-lg-none" 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 active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Settings</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Help</a>
</li>
</ul>
<form class="form-inline mt-2 mt-md-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>
</nav>
</header>
<div class="container-fluid">
<div class="row">
<nav class="col-sm-3 col-md-2 d-none d-sm-block bg-light sidebar">
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">Overview <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Reports</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Analytics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Export</a>
</li>
</ul>
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link" href="#">Nav item</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Nav item again</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">One more nav</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Another nav item</a>
</li>
</ul>
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link" href="#">Nav item again</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">One more nav</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Another nav item</a>
</li>
</ul>
</nav>
I have changed few styles, please add this to your css file..
<div class="row" style="position:relative;">
<nav class="col-sm-3 col-md-2 d-none d-sm-block bg-light sidebar" style="position:fixed; z-index:2000; top:0px;">