I am new with HTML and i downloaded a template that uses Tabs and this is how is rendered:
So What I need is to when I click on "Próximo" it changes the tabs to the next or other that I choose.
I tried to do something like that, but it didn't worked! :
<button type="button" class="btn btn-danger nav-link" aria-expanded="true" href="#Legal" data-toggle="tab">
Próximo
</button>
The code :
<ul class="nav nav-tabs mb-3">
<li class="nav-item">
<a href="#CompanyData" data-toggle="tab" aria-expanded="false" class="nav-link active">
<i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
<span class="d-none d-lg-block">Dados da Empresa</span>
</a>
</li>
<li class="nav-item">
<a href="#Legal" data-toggle="tab" aria-expanded="true"
class="nav-link">
<i class="mdi mdi-account-circle d-lg-none d-block mr-1"></i>
<span class="d-none d-lg-block">Cadastrar Empresa</span>
</a>
</li>
<li class="nav-item">
<a href="#listCompanies" data-toggle="tab" aria-expanded="false" class="nav-link">
<i class="mdi mdi-settings-outline d-lg-none d-block mr-1"></i>
<span class="d-none d-lg-block">Listar Empresas</span>
</a>
</li>
</ul>
And
<div class="tab-content">
<div class="tab-pane show active" id="CompanyData">
</div>
<div class="tab-pane " id="Legal">
</div>
<div class="tab-pane" id="listCompanies">
</div>
</div>
You can't make another buttons do the task of a tab button because internally bootstrap.js makes several changes to it. But what we can do is to simulate the click event and make the tab button click if we click our button.
Add a callback function on a click to our button as below
<button onclick="makeClick()" type="button" class="btn btn-danger nav-link" aria-expanded="true" href="#Legal" data-toggle="tab">
Próximo
</button>
Assign id to each li in list
<ul class="nav nav-tabs mb-3">
<li class="nav-item" >
<a href="#CompanyData" id="Dados" data-toggle="tab" aria-expanded="false" class="nav-link active">
<i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i><span class="d-none d-lg-block">Dados da Empresa</span>
</a>
</li>
<li class="nav-item">
<a href="#Legal" id="Cadastrar" data-toggle="tab" aria-expanded="true"
class="nav-link">
<i class="mdi mdi-account-circle d-lg-none d-block mr-1"></i><span class="d-none d-lg-block">Cadastrar Empresa</span>
</a>
</li>
<li class="nav-item">
<a href="#listCompanies" id="Listar" data-toggle="tab" aria-expanded="false" class="nav-link">
<i class="mdi mdi-settings-outline d-lg-none d-block mr-1"></i><span class="d-none d-lg-block">Listar Empresas</span>
</a>
</li>
And in your JS file create the below function:
makeClick(){
$('#Listar').click(); //this will simulate the click and Listar tab will be opened
}
Code:
function makeClick() {
$('#Cadastrar').click();
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js" integrity="sha384-6khuMg9gaYr5AxOqhkVIODVIvm9ynTT5J4V1cfthmT+emCG6yVmEZsRHdxlotUnm" crossorigin="anonymous"></script>
<ul class="nav nav-tabs mb-3">
<li class="nav-item">
<a href="#CompanyData" id="Dados" data-toggle="tab" aria-expanded="false" class="nav-link active">
<i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i><span class="d-lg-block"> Dados da Empresa </span>
</a>
</li>
<li class="nav-item">
<a href="#Legal" id="Cadastrar" data-toggle="tab" aria-expanded="true" class="nav-link">
<i class="mdi mdi-account-circle d-lg-none d-block mr-1"></i><span class="d-lg-block">Cadastrar Empresa</span>
</a>
</li>
<li class="nav-item">
<a href="#listCompanies" id="Listar" data-toggle="tab" aria-expanded="false" class="nav-link">
<i class="mdi mdi-settings-outline d-lg-none d-block mr-1"></i><span class="d-lg-block">Listar Empresas</span>
</a>
</li>
<div class="tab-content">
<div class="tab-pane show active" id="CompanyData" role="tabpanel">
Dados da Empresa Tab
<button onclick="makeClick()" type="button" class="btn btn-danger nav-link" aria-expanded="true" href="#Legal" data-toggle="tab">Próximo
</button>
</div>
<div class="tab-pane " id="Legal" role="tabpanel">
Cadastrar Empresa Tab
</div>
<div class="tab-pane" id="listCompanies" role="tabpanel">
Listar Empresas Tab
</div>
</div>
Related
im new to laravel and in my class project i want to take SB Admin2 template and use it on laravel, since i want to learn how is this made, i took the HTML version and made into sidebar, topbar and content components, rigth now im struggling with the side bar i made it dynamic so i can evaluate the role of the user and render the menus according to it, the sample nav-items work fine but my generated code doesn't, i can't see any diference, can someone give me an advice?
SIDEBAR GENERATED CODE
<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">
<!-- Sidebar - Brand -->
<a class="sidebar-brand d-flex align-items-center justify-content-center">
<div class="sidebar-brand-icon rotate-n-15">
<img src="http://127.0.0.1:8000/layout/img/rapidsoft_icon.png">
</div>
<div class="sidebar-brand-text mx-3">Rapisoft</div>
</a>
<!-- Divider -->
<hr class="sidebar-divider my-0">
<!-- Nav Item - Dashboard -->
<li class="nav-item active">
<a class="nav-link" href="http://127.0.0.1:8000/dashboard">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Dashboard</span></a>
</li>
<!-- Divider -->
<hr class="sidebar-divider">
<li class="nav-item">
<a class="nav-link" href="/home">
<i class="fas fa-fw fa-chart-area"></i>
<span>Home</span></a>
</li>
<!--GENERATED CODE-->
<li class="nav-item">
<a class="nav-link collapsed" href="/pages" data-toggle="collapse" data-target="#2collapsePages"
aria-expanded="true" aria-controls="2collapsePages">
<i class="fas fa-fw fa-folder"></i>
<span>Pages</span>
</a>
<div id="2collapsePages" class="collapse" aria-labelledby="headingPages"
data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<a class="collapse-item" href="/portfolio">Portfolio</a>
<a class="collapse-item" href="/gallery">Gallery</a>
</div>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="/our-services">
<i class="fas fa-fw fa-chart-area"></i>
<span>Our Services</span></a>
</li>
<!--GENERATED CODE-->
<li class="nav-item">
<a class="nav-link collapsed" href="/about" data-toggle="collapse" data-target="#4collapsePages"
aria-expanded="true" aria-controls="4collapsePages">
<i class="fas fa-fw fa-folder"></i>
<span>About</span>
</a>
<div id="4collapsePages" class="collapse" aria-labelledby="headingPages"
data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<a class="collapse-item" href="/about-team">About Team</a>
<a class="collapse-item" href="/about-clients">About Clients</a>
</div>
</div>
</li>
<!--GENERATED CODE-->
<li class="nav-item">
<a class="nav-link collapsed" href="/contact" data-toggle="collapse" data-target="#9collapsePages"
aria-expanded="true" aria-controls="9collapsePages">
<i class="fas fa-fw fa-folder"></i>
<span>Contact</span>
</a>
<div id="9collapsePages" class="collapse" aria-labelledby="headingPages"
data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<a class="collapse-item" href="/contact-team">Contact Team</a>
<a class="collapse-item" href="/contact-clients">Contact Clients</a>
</div>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="/pqr">
<i class="fas fa-fw fa-chart-area"></i>
<span>PQR</span></a>
</li>
<!--SAMPLE FROM SB ADMIN-->
<li class="nav-item">
<a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapsePages"
aria-expanded="true" aria-controls="collapsePages">
<i class="fas fa-fw fa-folder"></i>
<span>Paginas</span>
</a>
<div id="collapsePages" class="collapse" aria-labelledby="headingPages" data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<h6 class="collapse-header">Login Screens:</h6>
<a class="collapse-item" href="login.html">Login</a>
<a class="collapse-item" href="register.html">Register</a>
<a class="collapse-item" href="forgot-password.html">Forgot Password</a>
<div class="collapse-divider"></div>
<h6 class="collapse-header">Other Pages:</h6>
<a class="collapse-item" href="404.html">404 Page</a>
<a class="collapse-item" href="blank.html">Blank Page</a>
</div>
</div>
</li>
<!-- PARTE ESTATICA ABAJO -->
<!-- Divider -->
<hr class="sidebar-divider d-none d-md-block">
<!-- Sidebar Toggler (Sidebar) -->
<div class="text-center d-none d-md-inline">
<button class="rounded-circle border-0" id="sidebarToggle"></button>
</div>
<!-- Sidebar Message -->
<div class="sidebar-card d-none d-lg-flex">
<img class="sidebar-card-illustration mb-2" src="http://127.0.0.1:8000/layout/img/undraw_rocket.svg"
alt="...">
<p class="text-center mb-2"> Aca van las notas que se deban tener para cada cliente!!!</p>
</div>
</ul>```
I found the problem, this is the code i was using to generate the menu:
#if ($menu->parent_id === 0 && $menu->ChCount() === 0)
<li class="nav-item">
<a class="nav-link" href="/{{$menu->slug}}">
<i class="fas fa-fw fa-chart-area"></i>
<span>{{$menu->menu_title}}</span></a>
</li>
#else
#if ($menu->parent_id === 0 and $menu->ChCount() > 0)
<li class="nav-item">
<a class="nav-link collapsed" href="/{{$menu->slug}}" data-toggle="collapse" data-target="#{{$menu->id}}collapsePages"
aria-expanded="true" aria-controls="{{$menu->id}}collapsePages">
<i class="fas fa-fw fa-folder"></i>
<span>{{$menu->menu_title}}</span>
</a>
<div id="{{$menu->id}}collapsePages" class="collapse" aria-labelledby="headingPages" data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<h6 class="collapse-header"></h6>
#foreach($menu->children as $menu)
<a class="collapse-item" href="/{{$menu->slug}}">{{$menu->menu_title}}</a>
#endforeach
</div>
</div>
</li>
#endif
#endif
i found that the ID wasn't captured so it doesnt aplied any css to it, i changed this:
id="{{$menu->id}}collapsePages" for this id="collapse_id{{$menu->id}}" and problem solved.
This is a question similar to this one, but it is for Bootstrap 4.
I am not able to add right-justified entries on the BS4 navbar that stay visible both when collapsed and not collapsed. I spent one full afternoon without success.
This is my goal:
Here my current code (that works only when not collapsed):
<nav class="navbar navbar-light navbar-expand-xl border-bottom mainmenu sticky-top">
<a class="navbar-brand text-capitalize text-blur" href="/">
<img class="mr-1" src="/images/logo/favicon-32x32.png" alt="Logo">
<span class="">Portami in Pista</span>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#myTopMenu"
aria-controls="collapsableTopMen" aria-expanded="false" aria-label="[Menu]">
<span class="sr-only">[Menu]</span>
<span class="navbar-toggler-icon" title="[Menu]"/>
</button>
<div class="collapse navbar-collapse" id="collapsableTopMen">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/Schools/">
<i class="fa fa-motorcycle fa-rotate-315 text-danger" aria-hidden="true"/>
<span class="text-blur-danger">PiP Reparto Corse</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/Tracks/">
<i class="fa fa-flag-checkered text-primary" aria-hidden="true"/>
<span>Piste</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/Blog/le-guide-del-giovedi/">
<i class="fa fa-mortar-board text-primary" aria-hidden="true"/>
<span>Le guide del giovedì</span>
</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<!- START of section should be always visible -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownLang" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="famfamfam-flags it" title="Italiano"/>
<span class="d-inline d-xl-none">Italiano</span>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownLang">
<a class="dropdown-item" href="/AbpLocalization/ChangeCulture?cultureName=en&returnUrl=/">
<i class="famfamfam-flags gb" aria-hidden="true"/>
<span class="">English</span>
</a>
</div>
</li>
<!- END of section should be always visible -->
<li class="nav-item">
<a class="nav-link" href="/Account/Login"><i class="fa fa-sign-in"/> Log in</a>
</li>
</ul>
</div>
</nav>
Since you're using Bootstrap 4, this answer is more relevant to your question:
https://stackoverflow.com/a/41513784/171456 (see the last part)
The part that you always want to keep visible needs to be separate from any of the collapsible parts. Then use the order-* classes to position the items as desired:
Demo: https://codeply.com/p/ylDhhZtpiH
<nav class="navbar navbar-light navbar-expand-xl border-bottom mainmenu sticky-top justify-content-start">
<a class="navbar-brand text-capitalize text-blur" href="/">
<img class="mr-1" src="//placehold.it/32" alt="Logo">
<span class="">Portami in Pista</span>
</a>
<button class="navbar-toggler order-2 ml-1" type="button" data-toggle="collapse" data-target=".collapsable" aria-controls="collapsableTopMen" aria-expanded="false" aria-label="[Menu]">
<span class="sr-only">[Menu]</span>
<span class="navbar-toggler-icon" title="[Menu]"></span>
</button>
<!-- 1st collapse menu -->
<div class="collapse navbar-collapse collapsable flex-grow-0 flex-xl-grow-1 order-last" id="collapsableTopMen">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/Schools/">
<i class="fa fa-motorcycle fa-rotate-315 text-danger" aria-hidden="true"></i>
<span class="text-blur-danger">PiP Reparto Corse</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/Tracks/">
<i class="fa fa-flag-checkered text-primary" aria-hidden="true"></i>
<span>Piste</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/Blog/le-guide-del-giovedi/">
<i class="fa fa-mortar-board text-primary" aria-hidden="true"></i>
<span>Le guide del giovedì</span>
</a>
</li>
</ul>
</div>
<!-- always visible portion -->
<ul class="navbar-nav order-1 order-xl-last ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownLang" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-flag it" title="Italiano"></i>
<span class="d-inline d-xl-none">Italiano</span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownLang">
<a class="dropdown-item" href="#">
<i class="fas fa-flag-usa gb" aria-hidden="true"></i>
<span class="">English</span>
</a>
</div>
</li>
</ul>
<!-- 2nd collapse menu -->
<div class="collapse navbar-collapse collapsable flex-grow-0 order-last">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/Account/Login"><i class="fa fa-sign-in"></i> Log in</a>
</li>
</ul>
</div>
</nav>
https://codeply.com/p/ylDhhZtpiH
I did a small important fix to the good answer from Zim.
I fixed the "always visible" portion of the menu as he did not overlap the whole menu when it was collapsed.
Adding a custom .navbar-always-overlapped class, fixed it.
<nav class="navbar navbar-light navbar-expand-lg border-bottom mainmenu sticky-top justify-content-start">
<!-- same code from Zim here>
...
<!-- always visible portion. Note the 'navbar-always-overlapped' -->
<ul class="navbar-nav navbar-always-overlapped order-1 order-lg-last ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownLang" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-flag it" title="Italiano"></i>
<span class="d-inline d-lg-none">Italiano</span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownLang">
<a class="dropdown-item" href="#">
<i class="fas fa-flag-usa gb" aria-hidden="true"></i>
<span class="">English</span>
</a>
</div>
</li>
</ul>
<!-- 2nd collapse menu -->
<div class="collapse navbar-collapse collapsable flex-grow-0 order-last">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/Account/Login"><i class="fa fa-sign-in"></i> Log in</a>
</li>
</ul>
</div>
</nav>
and the code for .navbar-always-overlapped:
.navbar-always-overlapped .dropdown-menu {
position: absolute !important;
}
See https://codeply.com/p/9deLYTGblZ
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 have a Boostrap 4 navbar in Angular application with an external <div> associated. With BS3 everithing works like a charms, but with BS4 some behaviors seems to be changed. In particular i'm having trouble with the .collapse class.
With BS3 when i load the page the external div is shown, but with BS4 it's initially hidden. Moreover with BS3 when i resize the page the exernal div is automatically collapsed together with the navbar, whereas with BS4 it is not.
So my question is: what do i have to do to have the same exact behavior i had with Boostrap 3?
Here is my code:
<nav class="navbar navbar-expand-lg navbar-light px-0 py-0 mb-5">
<div class="container-fluid">
<div class="navbar-header" style="width: 100%">
<button type="button" class="navbar-toggler pull-right my-2" data-toggle="collapse" data-target=".navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="pull-left">
<img src="assets/images/image.png" width="200" height="100">
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="btn welcome"> Benvenuto <strong>{{ this.sessionUsername }}</strong>!</a></li>
<li class="nav-item"><a class="btn link" role="button" [routerLink]="['/login']" (click)="clearSessionStorage()"><i class="fa fa-sign-out"></i> Logout</a></li>
<li class="nav-item"><a class="btn link" role="button" data-toggle="modal" data-target="#changePasswordModal"><i class="fa fa-unlock-alt"></i> Cambio Password</a></li>
</ul>
</div>
</div>
</nav>
=== External div that give me troubles in responsiveness ===
<div class="navbar-collapse collapse col-lg-2 col-md-2 col-sm-3 col-xs-12" style="float: left">
<ul class="nav nav-pills flex-column">
<li class="nav-item" *ngIf="session.isCompanyVisible"><a class="nav-link link" [routerLink]="['./company']"><i class="fa fa-building-o"></i> Società </a></li>
<li class="nav-item" *ngIf="session.isDocTypeVisible"><a class="nav-link link" [routerLink]="['./document-type']"><i class="fa fa-file-text-o"></i> Tipo Documento </a></li>
<li class="nav-item" *ngIf="session.isConfigVisible"><a class="nav-link link" [routerLink]="['./configuration']"><i class="fa fa-cog"></i> Configurazione </a></li>
<li class="nav-item" *ngIf="session.isDomainsVisible"><a class="nav-link link" [routerLink]="['./domains']"><i class="fa fa-dot-circle-o"></i> Domini </a></li>
<li class="nav-item" *ngIf="session.isSignTypeVisible"><a class="nav-link link" [routerLink]="['./signature-type']"><i class="fa fa-pencil"></i> Firme </a></li>
<li class="nav-item" *ngIf="session.isMonitoringVisible"><a class="nav-link link" [routerLink]="['./monitoring']"><i class="fa fa-desktop"></i> Monitoraggio </a></li>
<li class="nav-item" *ngIf="session.isPDAManagementVisible"><a class="nav-link link" [routerLink]="['./pda-management']"><i class="fa fa-mobile fa-lg"></i> Gestione PDA </a></li>
</ul>
</div>
Its because of change in bootstarp's css
So you can solve your issue by apply some css to your external div as i applied in snippet
#media (min-width: 992px){
.external-collapse.navbar-collapse {
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
}
}
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
<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 px-0 py-0 mb-5">
<div class="container-fluid">
<div class="navbar-header" style="width: 100%">
<button type="button" class="navbar-toggler pull-right my-2" data-toggle="collapse" data-target=".navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="pull-left">
<img src="assets/images/image.png" width="200" height="100">
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="btn welcome"> Benvenuto <strong>{{ this.sessionUsername }}</strong>!</a></li>
<li class="nav-item"><a class="btn link" role="button" [routerLink]="['/login']" (click)="clearSessionStorage()"><i class="fa fa-sign-out"></i> Logout</a></li>
<li class="nav-item"><a class="btn link" role="button" data-toggle="modal" data-target="#changePasswordModal"><i class="fa fa-unlock-alt"></i> Cambio Password</a></li>
</ul>
</div>
</div>
</nav>
=== External div that give me troubles in responsiveness ===
<div class="external-collapse navbar-collapse collapse col-lg-2 col-md-2 col-sm-3 col-xs-12" style="float: left">
<ul class="nav nav-pills flex-column">
<li class="nav-item" *ngIf="session.isCompanyVisible"><a class="nav-link link" [routerLink]="['./company']"><i class="fa fa-building-o"></i> Società </a></li>
<li class="nav-item" *ngIf="session.isDocTypeVisible"><a class="nav-link link" [routerLink]="['./document-type']"><i class="fa fa-file-text-o"></i> Tipo Documento </a></li>
<li class="nav-item" *ngIf="session.isConfigVisible"><a class="nav-link link" [routerLink]="['./configuration']"><i class="fa fa-cog"></i> Configurazione </a></li>
<li class="nav-item" *ngIf="session.isDomainsVisible"><a class="nav-link link" [routerLink]="['./domains']"><i class="fa fa-dot-circle-o"></i> Domini </a></li>
<li class="nav-item" *ngIf="session.isSignTypeVisible"><a class="nav-link link" [routerLink]="['./signature-type']"><i class="fa fa-pencil"></i> Firme </a></li>
<li class="nav-item" *ngIf="session.isMonitoringVisible"><a class="nav-link link" [routerLink]="['./monitoring']"><i class="fa fa-desktop"></i> Monitoraggio </a></li>
<li class="nav-item" *ngIf="session.isPDAManagementVisible"><a class="nav-link link" [routerLink]="['./pda-management']"><i class="fa fa-mobile fa-lg"></i> Gestione PDA </a></li>
</ul>
</div>