Two-column collapsed navbar in Bootstrap 5 doesn't work - html

I'm making this Bootstrap 5 navbar, which should collapse at md breakpoint. After the collapse, it should show navlinks in two columns.
When I hit the breakpoint, my navbar is expanded and toggle button doesn't work.
It changes, when I switch off the display: flex property for the navbar - the collapse function works, but my ul's (in which I group li's) are in one column.
How can I reach my goal here - navbar with six elements collapses at md breakpoint and breaks the links into two columns?
<nav class="navbar navbar-expand-md navbar-light sticky-top w-100">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNavbar"
aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNavbar">
<ul class="navUl navbar-nav">
<li class="nav-item">
<a class="nav-link text-nowrap" aria-current="page" href="/aboutMe">o mnie</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
data-bs-toggle="dropdown" aria-expanded="false">portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link text-nowrap" href="/beforePS">przed sesją</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link navbar-brand" href="/">
<img src="/images/logoKP-trans.png" class="img-fluid" alt="Karolina_photography_logo" id="logo">
</a>
</li>
</ul>
<ul class="navUl navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/voucher">vouchery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/pricing">pakiety</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact">kontakt</a>
</li>
</ul>
</div>
css (very messy, to be optimised):
body {
background-color: #f8edeb;
margin: 0;
font-family: "Quicksand", sans-serif;
font-weight: 400;
opacity: 0;
animation: fadeIn 0.5s;
transition: opacity 0.5s;
}
main {
align-items: center;
margin: 3% 20%;
max-width: 80%;
}
.navbar,
.footer {
background-color: #fae1dd;
color: rgba(0, 0, 0, 0.5);
box-shadow: 10px 5px 5px rgba(202, 178, 174, 0.5);
padding-top: 0;
text-align: center;
}
#mainNavbar {
display: flex;
justify-content: center;
align-items:flex-end;
}
.navbar-brand {
margin: 0;
}
.nav-item {
display: flex;
margin: 0 0.8em;
font-size: 1.2rem;
}
.navUl {
padding-bottom: 10px;
}
.navbar-brand {
max-width: 300px;
height: auto;
padding-bottom: 0;
top: 0.4rem;
}
#mainNavbar a:hover,
#socialIcons a:hover,
.loginButton a:hover {
color: white;
text-shadow: 5px 5px 10px white;
-moz-transition: all 0.2s ease-in;
-o-transition: all 0.2s ease-in;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.dropdown-menu {
border-radius: 0.5rem;
background-color: rgba(250, 225, 221, 0.9);
}
.dropdown-item:hover {
background-color: transparent;
}
#socialIcons {
color: rgba(0, 0, 0, 0.5);
position: absolute;
top: 10px;
right: 10px;
}
#socialIcons a,
#kidsPshoot {
text-decoration: none;
color: rgba(0, 0, 0, 0.5);
display: inline;
margin-right: 0.5rem;
}
.fade_rule {
height: 1px;
background-color: #e6e6e6;
width: 50%;
margin: 0 auto;
background-image: linear-gradient(left, white 2%, #e6e6e6 50%, white 98%);
background-image: -o-linear-gradient(left, white 2%, #e6e6e6 50%, white 98%);
background-image: -moz-linear-gradient(
left,
white 2%,
#e6e6e6 50%,
white 98%
);
background-image: -webkit-linear-gradient(
left,
white 2%,
#e6e6e6 50%,
white 98%
);
background-image: -ms-linear-gradient(left, white 2%, #e6e6e6 50%, white 98%);
background-image: -webkit-gradient(
linear,
left bottom,
right bottom,
color-stop(0.02, white),
color-stop(0.5, rgb(250, 182, 170)),
color-stop(0.98, white)
);
}
#media (max-width:1200px) {
.nav-item, .dropdown-item, #aboutMeText, p, li, h5 {
font-size: 1rem;
}
#logo {
max-width: 230px;
}
.navUl {
padding-bottom: 5px;
}
}
#media (max-width:992px) {
#logo {
max-width: 200px;
/* position: absolute;
left: 70%;
top: 30%; */
}
.nav-item, .dropdown-item {
font-size: 0.9rem;
}
.nav-item {
margin: 0;
}
}
#media (max-width:768px) {
.nav-item, .dropdown-item, #navbarDropdownMenuLink, p, li {
font-size: 0.7rem;
margin-left: 0;
text-align: left;
min-width: 100px;
}
#mainNav {
position:unset;
}
}

It’s not clear what all of your CSS is for. Some, like setting the opacity on the body to 0 hide everything. It’s best to have a running snippet with your question.
If you want your logo in the center, you can split your menus into two unordered lists.
For applying margin such as to the bottom of the navbar-nav, use the Bootstrap spacing utility classes (mb-1 mb-md-2).
Copy the Bootstrap media query logic (min-width, not max-width – it’s difficult to troubleshoot with two methods) and apply your media queries starting with the smallest size (no media query), followed by increasing media query sizes (min-width: 576px, min-width: 768px, etc.).
Rather than using smaller text for smaller screens, keep the text the same size and adjust the position if the text won’t fit (smaller text is more difficult for some users to read).
One way to have two columns for the links in the collapsed version is to add a spacer div (.break) that can force the navbar-collapse divs to the next row, and then set their width to 50%.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.bundle.min.js"></script>
<style>
body {
background-color: #f8edeb;
font-family: "Quicksand", sans-serif;
}
.navbar,
.footer {
background-color: #fae1dd;
color: rgba(0, 0, 0, 0.5);
box-shadow: 10px 5px 5px rgba(202, 178, 174, 0.5);
padding-top: 0;
}
.navbar-brand {
margin: 0;
max-width: 300px;
height: auto;
padding-bottom: 0;
top: 0.4rem;
}
#mainNavbar a:hover,
#socialIcons a:hover,
.loginButton a:hover {
color: white;
text-shadow: 5px 5px 10px white;
-moz-transition: all 0.2s ease-in;
-o-transition: all 0.2s ease-in;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.dropdown-menu {
border-radius: 0.5rem;
background-color: rgba(250, 225, 221, 0.9);
max-width: 75%;
}
.dropdown-item:hover {
background-color: #E0C9C5;
}
#logo {
max-width: 120px;
height: auto;
}
#media (min-width: 576px) {
#logo {
max-width: 160px;
}
}
#media (min-width: 768px) {
#logo {
max-width: 200px;
}
.navbar-collapse.flex-basis-md-0 {
flex-basis: 0;
}
}
#media (min-width: 992px) {
#logo {
max-width: 230px;
}
}
#media (min-width: 1200px) {
#logo {
max-width: 300px;
}
}
.navbar-collapse {
max-width: 50%;
}
/* Inserting div.break between two flex items will make
* the flex item that comes after it break to a new row -
* this is how the two-column navbar-collapse are moved to
* a separate row. */
.break {
flex-basis: 100%;
height: 0;
}
#media (min-width: 768px) {
.break {
display: none;
}
}
</style>
<nav class="navbar navbar-expand-md navbar-light sticky-top w-100">
<div class="container-fluid justify-content-md-around">
<a class="navbar-brand order-md-1" href="#">
<img id="logo" src="https://via.placeholder.com/120x40.png/E5FFFF/?text=KP-Trans" alt="" width="300" height="60">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".mainNavbar" aria-controls="mainNavbar1 mainNavbar2" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="break"></div>
<div class="collapse navbar-collapse flex-basis-md-0 mainNavbar" id="mainNavbar1">
<ul class="navbar-nav mx-md-auto">
<li class="nav-item">
<a class="nav-link text-nowrap" aria-current="page" href="/aboutMe">o mnie</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
portfolio
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">portfolio #1</a></li>
<li><a class="dropdown-item" href="#">portfolio #2</a></li>
<li><a class="dropdown-item" href="#">portfolio #3</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link text-nowrap" href="/beforePS">przed sesją</a>
</li>
</ul>
</div>
<div class="collapse navbar-collapse flex-basis-md-0 align-self-start align-self-md-center mainNavbar order-md-2" id="mainNavbar2">
<ul class="navbar-nav mx-md-auto">
<li class="nav-item">
<a class="nav-link" href="/voucher">vouchery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/pricing">pakiety</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact">kontakt</a>
</li>
</ul>
</div>
</div>
</nav>
<section>
<div class="container">
<div class="row">
<div class="col vh-100">
<p class="text-center">
Center
</p>
</div>
</div>
</div>
</section>
It's also helpful if you include a placeholder image at the right size to match your logo. I guessed at 120 by 40

Related

Bootstrap 3 Upgrade to Bootstrap 5 NavBar Issue

I am responsible for upgrading Bootstrap from 3 to 5, and allow some minor UI changes, like px-wise changes. However I am suffering from navbar transition like the below discussed.
Here is the simplified version of my navbar using Bootstrap 3.
.image-header-logo {
margin: -5px;
height: 34px;
}
.custom-navbar {
box-shadow: 0px 0px 6px rgb(255 100 0);
}
.navbar {
border: 0px;
}
.navbar-nav > li.active {
box-shadow: inset 0px -5px 0px 0px rgba(255, 119, 0, 0.68);
}
.navbar-nav > li > a {
color: #ff6633;
}
.navbar-nav > li > a:hover {
background: rgb(255, 119, 0);
color: #ffffff;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar custom-navbar">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img class="image-header-logo" src="https://www.gravatar.com/avatar/e8bf61002bf07be4ca6085c301f990c0?s=64" />
</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right" >
<li><a class="nav-menu-item">Welcome</a></li>
<li class="active">
<a class="nav-selected-menu-item nav-text-color" href="#">Java</a>
</li>
<li>
<a class="nav-selected-menu-item nav-text-color" href="#">PHP</a>
</li>
</ul>
</div>
</div>
</nav>
And here is the new code using Bootstrap 5.
body {
font-size: 14px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
.image-header-logo {
height: 2.5rem;
}
.navbar {
padding: 0 1rem;
margin-bottom: 6px;
}
.custom-navbar {
box-shadow: 0px 0px 6px rgb(255 100 0);
}
.nav-item {
cursor: pointer;
padding: 0.5rem 0;
}
.navbar .navbar-collapse .navbar-nav .nav-item.active {
box-shadow: inset 0px -5px 0px 0px rgba(255, 119, 0, 0.68);
cursor: pointer;
}
.navbar .navbar-collapse > .navbar-text,
.navbar .navbar-collapse .navbar-nav .nav-item > .nav-link {
color: #ff6633;
}
.navbar .navbar-collapse .navbar-nav .nav-item:hover {
background: rgb(255, 119, 0);
color: #ffffff; /* FIXME: not work == */
}
/* FIXME: need to add this, but in the outskirt it does not work */
.navbar .navbar-collapse .navbar-nav .nav-item > .nav-link:hover {
color: #ffffff;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-md navbar-light custom-navbar">
<a class="navbar-brand" href="/i/trade">
<img class="image-header-logo" src="https://www.gravatar.com/avatar/e8bf61002bf07be4ca6085c301f990c0?s=64" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#myNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="myNavbar">
<span class="navbar-text ms-auto">Welcome</span>
<ul class="navbar-nav">
<li class="nav-item active px-1">
<a class="nav-link">Java</a>
</li>
<li class="nav-item px-1">
<a class="nav-link">PHP</a>
</li>
</ul>
</div>
</nav>
As it seems there is a rendering issue in stackoverflow, I have also place the code in jsfiddle.
The same codebase can also be found in jsfiddle.
Bootstrap 3: https://jsfiddle.net/hphchan/hfo9njc3/66/
Bootstrap 5: https://jsfiddle.net/hphchan/4yrxu8dk/60/
Most of the UI generated from the 2 version looks similar, but with the below issue.
When hover on nav-item but not nav-link in Bootstrap 5, as there is a padding in nav-item, making the hover color changes not work.
which can be seen in the picture below.
And here is the Bootstrap 3 version, which works in the edge.
I understand why it does not work due to the class structure change. However what I do not know is how to make the hover behavior the same.
You can emulate the behavior using the hover selector only for the nav-link class and forgetting the nav-item to simplify what style applies when hovered.
This way nav-link should have color: #ff6633 when not hovered and color: #ffffff when hovered:
.navbar .navbar-collapse>.navbar-text,
.navbar .navbar-collapse .navbar-nav .nav-item>.nav-link {
color: #ff6633;
}
.navbar .navbar-collapse .navbar-nav .nav-item>.nav-link:hover {
color: #ffffff;
background: rgb(255, 119, 0);
}
Also, remove the ** margin-bottom ** property for the .navbar.
The markup for the ul would be:
<ul class="navbar-nav">
<li class="nav-item active mx-2">
<a class="nav-link py-3 px-3">Java</a>
</li>
<li class="nav-item ms-2">
<a class="nav-link py-3 px-3">PHP</a>
</li>
</ul>
Working example:
body {
font-size: 14px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.image-header-logo {
height: 2.5rem;
}
.navbar {
padding: 0 1rem;
/* override default 0.5rem 1rem */
/* box-shadow: 0px 0px 6px rgb(255, 100, 0); */
/* TODO: placed in #header instead */
margin-bottom: 6px;
/* reserve space for the box-shadow */
}
.custom-navbar {
box-shadow: 0px 0px 6px rgb(255 100 0);
}
/* to create sadow on the bottom */
.nav-item {
cursor: pointer;
}
.navbar .navbar-collapse .navbar-nav .nav-item.active>.nav-link {
box-shadow: inset 0px -5px 0px 0px rgba(255, 119, 0, 0.68);
cursor: pointer;
}
/* to show orange in color on the line */
/* need to specify for so long, so that it can win without use of !important... == */
.navbar .navbar-collapse>.navbar-text,
.navbar .navbar-collapse .navbar-nav .nav-item>.nav-link {
color: #ff6633;
}
/* FIXME: need to add this, but in the outskirt it does not work */
.navbar .navbar-collapse .navbar-nav .nav-item>.nav-link:hover {
color: #ffffff;
background: rgb(255, 119, 0);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css">
<nav class="navbar navbar-expand navbar-light custom-navbar py-0">
<a class="navbar-brand" href="/i/trade">
<img class="image-header-logo" src="https://www.gravatar.com/avatar/e8bf61002bf07be4ca6085c301f990c0?s=64" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#myNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="myNavbar">
<span class="navbar-text ms-auto">Welcome</span>
<ul class="navbar-nav">
<li class="nav-item active mx-2">
<a class="nav-link py-3 px-3">Java</a>
</li>
<li class="nav-item ms-2">
<a class="nav-link py-3 px-3">PHP</a>
</li>
</ul>
</div>
</nav>

Dropwdown arrow over text in navbar

I'm trying to have a dropdown on a navbar item. It works, but the arrow is over the text of the menu item.
Codepen:
https://codepen.io/ogonzales/pen/QWjmorP
Code
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark" style="height: 70px;">
<a class="navbar-brand" href="#">Fixed navbar</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" id="navbarCollapse">
<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">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</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">
More
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/support/">Support and Consulting</a>
<a class="dropdown-item" href="/test-driven-development/">What is Test-Driven Development?</a>
<a class="dropdown-item" href="/testimonials/">Testimonials</a>
</div>
</li>
</ul>
<form class="form-inline ml-auto">
Log in
Sign up
</form>
</div>
</nav>
Bonus
I'd like also to put every navbar item more to the right. I know I can do this with CSS, but is there a Boostrap class am I missing?
You ul tag was not closed, I fixed that and answered your bonus question as well.
The reason it was on the over the text because, both the dropdown and the link were within same block, so you have to specify the width for those to fit-in inline, I have just provided 100px under .nav-link{...} and you are free to change that as per you requirement.
To move contents towards right you can have width property for the yellow block(check in my snipppet/fiddle) OR you can provide flex option for the block and use 'justify-content:space-between;`.
View in full screen due to media-query you have used.
.nav-link{
border:1px solid yellow;
margin:5px;
width:100px;
}
fiddle to playground.
$(document).ready(function() {
$('#sidebarCollapse').on('click', function() {
$('#sidebar').toggleClass('active');
});
});
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
font-size: 14px;
}
#media (min-width: 768px) {
html {
font-size: 16px;
}
}
body {
margin-bottom: 60px;
/* Margin bottom by footer height */
font-family: 'Poppins', sans-serif;
background: #fafafa;
padding-top: 70px;
}
.container {
max-width: 960px;
}
.pricing-header {
max-width: 700px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
/* Set the fixed height of the footer here */
line-height: 60px;
/* Vertically center the text there */
background-color: #f5f5f5;
}
/* NAVBAR TOP */
#top-navbar ul li.active>a a[aria-expanded="true"] {
color: #1f1f1f;
background: #12b556;
}
#top-navbar a:visited {
color: #fff;
}
#top-navbar a:link {
color: #fff;
}
#top-navbar a.subitem:link {
color: #1f1f1f;
}
/* ==== */
/* SIDEBAR */
/* ---------------------------------------------------
SIDEBAR STYLE
----------------------------------------------------- */
.wrapper {
display: flex;
align-items: stretch;
}
#sidebar {
min-width: 250px;
max-width: 250px;
background: #1f1f1f;
color: #fff;
transition: all 0.3s;
}
#sidebar.active {
min-width: 80px;
max-width: 80px;
text-align: center;
}
#sidebar.active .sidebar-header h3,
#sidebar.active .CTAs {
display: none;
}
#sidebar.active .sidebar-header strong {
display: block;
}
#sidebar ul li a {
text-align: left;
}
#sidebar.active ul li a {
padding: 20px 10px;
text-align: center;
font-size: 0.85em;
}
#sidebar.active ul li a i {
margin-right: 0;
display: block;
font-size: 1.8em;
margin-bottom: 5px;
}
#sidebar.active ul ul a {
padding: 10px !important;
}
#sidebar.active .dropdown-toggle::after {
top: auto;
bottom: 10px;
right: 50%;
-webkit-transform: translateX(50%);
-ms-transform: translateX(50%);
transform: translateX(50%);
}
#sidebar .sidebar-header {
padding: 20px;
background: #1f1f1f;
}
#sidebar .sidebar-header strong {
display: none;
font-size: 1.8em;
}
#sidebar ul.components {
padding: 20px 0;
border-bottom: 1px solid #47748b;
}
#sidebar ul li a {
padding: 10px;
font-size: 1.1em;
display: block;
}
#sidebar ul li a:hover {
color: #12b556;
background: #fff;
}
#sidebar ul li a i {
margin-right: 10px;
}
#sidebar ul li.active>a.sidebar-link a[aria-expanded="true"] {
color: #fff;
background: #12b556;
}
a[data-toggle="collapse"] {
position: relative;
}
#navbarCollapse {
border: 1px solid red;
}
.nav-link {
border: 1px solid yellow;
margin: 5px;
width: 100px;
}
.dropdown-toggle::after {
display: block;
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
}
ul ul a {
font-size: 0.9em !important;
padding-left: 30px !important;
background: #12b556;
}
ul.CTAs {
padding: 20px;
}
ul.CTAs a {
text-align: center;
font-size: 0.9em !important;
display: block;
border-radius: 5px;
margin-bottom: 5px;
}
a.download {
background: #fff;
color: #12b556;
}
a.article,
a.article:hover {
background: #12b556 !important;
color: #fff !important;
}
a.sidebar-link:visited {
color: #fff;
}
a.sidebar-link:link {
color: #fff;
}
/* ---------------------------------------------------
CONTENT STYLE
----------------------------------------------------- */
#content {
width: 100%;
padding: 20px;
min-height: 100vh;
transition: all 0.3s;
}
/* ---------------------------------------------------
MEDIAQUERIES
----------------------------------------------------- */
#media (max-width: 768px) {
#sidebar {
min-width: 80px;
max-width: 80px;
text-align: center;
margin-left: -80px !important;
}
.dropdown-toggle::after {
top: auto;
bottom: 10px;
right: 50%;
-webkit-transform: translateX(50%);
-ms-transform: translateX(50%);
transform: translateX(50%);
}
#sidebar.active {
margin-left: 0 !important;
}
#sidebar .sidebar-header h3,
#sidebar .CTAs {
display: none;
}
#sidebar .sidebar-header strong {
display: block;
}
#sidebar ul li a {
padding: 20px 10px;
}
#sidebar ul li a span {
font-size: 0.85em;
}
#sidebar ul li a i {
margin-right: 0;
display: block;
}
#sidebar ul ul a {
padding: 10px !important;
}
#sidebar ul li a i {
font-size: 1.3em;
}
#sidebar {
margin-left: 0;
}
#sidebarCollapse span {
display: none;
}
}
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<title>{% block title %}DjangoX{% endblock title %}</title>
<meta name="description" content="A framework for launching new Django projects quickly.">
<meta name="author" content="">
<link rel="shortcut icon" type="image/x-icon" href="{% static 'images/favicon.ico' %}">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link href="https://use.fontawesome.com/releases/v5.12.0/css/all.css" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<link rel="stylesheet" href="{% static 'css/price.css' %}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#sidebarCollapse').on('click', function() {
$('#sidebar').toggleClass('active');
});
});
</script>
</head>
<body>
<!--MENU SUPERIOR-->
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark" style="height: 70px;">
<a class="navbar-brand" href="#">Fixed navbar</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" id="navbarCollapse">
<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">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</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">
More
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/support/">Support and Consulting</a>
<a class="dropdown-item" href="/test-driven-development/">What is Test-Driven Development?</a>
<a class="dropdown-item" href="/testimonials/">Testimonials</a>
</div>
</li>
</ul>
<form class="form-inline ml-auto">
Log in
Sign up
</form>
</div>
</nav>
<!-- FIN MENU SUPERIOR-->
<div class="wrapper">
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-header">
<img src="static\images\elim-logo.png" alt="Ministerios Elim" width="50%" height="50%">
<strong>ELIM</strong>
</div>
<ul class="list-unstyled components">
<li class="">
<a class="sidebar-link" href="#capitulo1" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">
<i class="fas fa-home"></i> Capítulo 1
</a>
<ul class="collapse list-unstyled" id="capitulo1">
<li>
<a class="sidebar-link" href="#">Introducción</a>
</li>
<li>
<a class="sidebar-link" href="#">¿Qué es la salvación?</a>
</li>
<li>
<a class="sidebar-link" href="#">¿Se pierde la salvación?</a>
</li>
</ul>
</li>
</ul>
</nav>
<!-- Page Content -->
<div id="content">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<button type="button" id="sidebarCollapse" class="btn btn-info">
<i class="fas fa-align-left"></i>
<span>Toggle Sidebar</span>
</button>
</div>
</nav>
<hr><br>
<main role="main" class="container">
<div class="row">
<div class="col-md-8">
{% block content %} {% endblock content %}
</div>
<div class="col-md-4 float-right" id="LocalSide">
<form class="search-form" action="/search/" method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="KTlYgVaxnAYKzLle9WWDNIoE0MDSvAVldfbsnKbfpAStWafCb1MVMgwLdArZUEiP">
<div class="form-group">
<input type="search" class="form-control search-course" placeholder="Buscar curso" name="search_term" required="">
<input type="hidden" value="3" name="course_id">
</div>
</form>
<h2 class="local-side-heading">In this Section:</h2>
<nav class="local-nav">
<ol data-local-nav-list=""></ol>
</nav>
<a class="pcta" href="/payments/tdd-flask/" data-a-buy-course-cta="tdd-flask">
<span class="label label-success">
<span class="pcta-label">Get the</span>
<span class="pcta-hook">full course</span>
<span class="sr-only">for</span>
<span class="pcta-badge" aria-hidden="true">Now Only</span>
</span>
<span class="pcta-price">$30</span>
</a>
↑ Back to top
</div>
</div>
</main>
<footer class="footer">
<div class="container">
<span class="text-muted">Footer...</span>
</div>
</footer>
</div>
</div>
In your code ".dropdown-toggle::after" right value is the problem, change into this code it will work.
.dropdown-toggle::after {
display: block;
position: absolute;
top: 50%;
right: -7px;
transform: translateY(-50%);
}
Just remove the below manual css u have designed. bcz it is overriding bootstrap's default css which is not appropiate
.dropdown-toggle::after {
display: block;
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
}

Angular CLI: Navbar Won't Collapse

I'm build a SPA app with Angular-CLI and Node.Js, using WebStorm, and I can't figure out why my navbar won't collapse.
When the page is small enough, the nav-items simply disappear.
I'm not using the navbar-expand class (instead using the navbar-expand-sm which isn't supposed to prevent collapsing), and other than that, I found nothing that's supposed to cause this problem.
My navbar.component.html:
<nav class="navbar navbar-expand-sm navbar-brown fixed-top">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" (click)="clickedHome()">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" (click)="clickedForums()">Forums</a>
</li>
<li class="nav-item">
<a class="nav-link" (click)="clickedMyZone()">MyZone</a>
</li>
</ul>
</div>
</nav>
<div class="jumbotron text-center" id="primary_jumbotron_display">
<div id="primaryDisplayBorder">
<div id="primaryDisplayContent">{{primaryDisplayBorderTitle}}</div>
<p>{{primaryDisplayBorderContent}}</p>
</div>
</div>
My navbar.component.css:
#import url(//db.onlinewebfonts.com/c/460e8698563db983434874f8f371a7d1?family=Museo);
.jumbotron {
height: 40vh;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#primary_jumbotron_display {
background-image: url('client/assets/images/FriendLancer_banner.jpg');
font-family: Museo;
font-size: x-large;
background-size: cover;
align-content: center;
color: saddlebrown;
margin-bottom: 0;
}
#primaryDisplayContent {
font-size: 7ex;
}
.navbar-brown {
background-color: saddlebrown !important;
box-shadow: #222222;
}
.navbar {
-webkit-box-shadow: 0 8px 6px -6px black;
-moz-box-shadow: 0 8px 6px -6px black;
box-shadow: 0 8px 6px -6px black;
}
.navbar-nav {
font-family: Museo;
font-size: medium;
}
.navbar-nav > li {
padding-left: 15px;
padding-right: 15px;
}
.nav-item {
transition: all 0.3s ease;
}
.navbar-nav a {
color: silver;
}
.navbar-nav a:hover {
color: saddlebrown;
letter-spacing: 1.3px;
background-image: linear-gradient(to right, sandybrown, rosybrown);
}
Any help would be appreciated.

How to hover splitted button in Bootstrap 4 navbar

For a Bootstrap 4 website I've made a navbar with splitted dropdown buttons. The leftside of the dropdown button is a normal link and the rightside is a caret button to show the submenu.
For some reason I cannot find a working CSS way to have the hover effect only on the rightside (caret) and not on the leftside (link). Is there a CSS way (without Javascript) to do this?
Thanx in advance.
You'll find the jsfiddle on https://jsfiddle.net/bnsthp57/
Update
The hover is working! The updated snippet below is ready to use. Tested on Internet Explorer 11, Crhome 79, Opera 66, Edge 44, and Firefox 72.
#topnav .navbar-nav {
font-size: 0rem;
}
#topnav .nav-link {
display: inline-block;
padding: 0.625rem 1rem;
font-size: 1rem;
}
#topnav .dropdown-link {
padding: 0.625rem 0.25rem;
}
#topnav .dropdown-toggle {
padding-left: 0.25rem;
}
#media (max-width: 767.98px) {
#topnav .navbar-nav {
padding-top: 0.5rem;
}
#topnav .nav-link:first-child,
#topnav .dropdown-link {
display: block;
width: calc(100% - 50px);
padding: 0.625rem 1rem;
border-right: 1px solid #88d;
}
#topnav .dropdown-toggle {
display: block;
width: 50px;
padding: 0.625rem 0.5rem;
position: absolute;
top:0; right:0;
text-align: center;
}
}
#media (min-width: 768px) {
#topnav .nav-link {
border-right: 1px solid rgba(0, 0, 0, 0.1);
}
#topnav .dropdown-link,
#topnav .nav-item:last-child a.nav-link {
border-right: 0;
}
#topnav .dropdown-menu {
margin-top: 0;
}
#topnav .dropdown-toggle:hover + .dropdown-menu,
#topnav .dropdown-menu:hover {
display: block; /* open submenu on hover */
}
#topnav .dropdown-menu:not(:hover) {
display: none; /* close submenu on not hover */
}
}
/* navbar theme */
#navbar,
#navbar .navbar-toggler {
color: #fff;
background-color: #1c8cbc;
border-color: #1f90bb #1f90bb #145e7a;
}
#navbar .navbar-toggler-icon {
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3e%3cpath stroke='rgba(255, 255, 255, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
#topnav .nav-link {
color: #fff;
background-color: transparent;
font-weight: 600;
}
#topnav .nav-link:hover {
background-color: rgba(0, 0, 0, 0.1);
}
#topnav .dropdown-menu,
#topnav .dropdown-item,
#topnav .dropdown-item:focus {
color: #fff;
background-color: #0c7cac;
}
#topnav .dropdown-item.active {
color: #ff6;
background-color: #0c7cac;
font-weight: 600;
}
#topnav .dropdown-item:hover,
#topnav .dropdown-item:active {
color: #fff;
background-color: #1383af;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<nav id="navbar" class="navbar navbar-expand-md mr-auto">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#topnav" aria-controls="topnav" aria-expanded="false"
aria-label="Toggle menu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="topnav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#pagelink">Home</a>
</li>
<li class="nav-item dropdown active">
<a class="nav-link dropdown-link" href="#pagelink">Magazine</a>
<a class="nav-link dropdown-toggle" href="#" id="navlink01" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></a>
<div class="dropdown-menu" aria-labelledby="navlink01">
<a class="dropdown-item" href="#pagelink">Sub item 1</a>
<a class="dropdown-item active" href="#pagelink">Sub item 2</a>
<a class="dropdown-item" href="#pagelink">Sub item 3</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="index.php">Portfolio</a>
</li>
</ul>
</div>
</div>
</nav>
Navbar with splitted dropdown buttons
.dropdown-toggle:hover + .dropdown-menu{
display:block;
}
With this css it will work
#media (min-width: 768px) {
#topnav .dropdown-toggle:hover + .dropdown-menu,
#topnav .dropdown-menu:hover {
display: block;
}
#topnav .dropdown-menu:not(:hover) {
display: none;
}
}
on this dropdown nav-item
<li class="nav-item dropdown active">
<a class="nav-link dropdown-link" href="#pagelink">Magazine</a>
<a class="nav-link dropdown-toggle" href="#" id="navlink01" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></a>
<div class="dropdown-menu" aria-labelledby="navlink01">
<a class="dropdown-item" href="#pagelink">Sub item 1</a>
<a class="dropdown-item active" href="#pagelink">Sub item 2</a>
<a class="dropdown-item" href="#pagelink">Sub item 3</a>
</div>
</li>

Making message appear in the middle of screen

I recently started to play round with Bootstrap and I created my logo to go on the top left of the page, and then the nav bar to go on the same line but on the right hand side, and then I wanted to say in the middle of the screen: "Welcome blablah"
However, the welcome bit appears on the top part of the screen, rather then the middle, so it's overlapping the logo for some reason.
Not sure why this is doing this, guessing some bad coding etc.
body {
font-family: 'Open Sans', sans-serif, Arial;
font-size: 16px;
color: #6D6D6D;
background-color: #F5F5F5;
font-weight: 300;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: 'Montserrat', sans-serif, Arial;
padding-bottom: 5px;
color: #373432;
line-height: 1em;
font-weight: normal;
}
a {
text-decoration: none;
outline: none;
}
.parallax {
background-image: url("../Images/back1.jpg");
min-height: 1000px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
width: 100%;
}
.logo {
float: left;
padding-top: 50px;
padding-left: 40px;
}
.logo h1 {
text-transform: uppercase;
font-weight: 900;
font-size: 60px;
letter-spacing: -5px;
line-height: 50px;
color: white;
}
.navbar-nav>li>a {
line-height: 6px;
}
.navbar {
float: right;
padding-top: 53px;
padding-right: 60px;
font-size: 13px;
text-transform: uppercase;
}
.navbar-default {
background-color: transparent;
border-top: 0px solid rgba(0, 0, 0, 0.5);
border-bottom: 0px solid rgba(0, 0, 0, 0.5);
border-left: 0px solid rgba(0, 0, 0, 0.5);
border-right: 0px solid rgba(0, 0, 0, 0.5);
}
.navbar-default .navbar-nav>li>a {
color: #ffffff;
}
.navbar-default .navbar-nav>li>a:hover,
.navbar-default .navbar-nav>li>a:focus {
background-color: #F8BD23;
text-decoration: none;
color: #ffffff;
-webkit-transition: background-color 200ms linear;
-moz-transition: background-color 200ms linear;
-o-transition: background-color 200ms linear;
-ms-transition: background-color 200ms linear;
transition: background-color 200ms linear;
}
.navbar-nav>li {
padding-left: 30px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="parallax">
<div class="logo"><img src="http://placehold.it/50x50"></div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button aria-controls="navbar" aria-expanded="false" class="navbar-toggle collapsed" data-target="#navbar" data-toggle="collapse" type="button"><span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span></button>
</div>
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav">
<li>
Home
</li>
<li>
a
</li>
<li>
b
</li>
<li>
c Us
</li>
<li>
d
</li>
<li>
e
</li>
<li>
f
</li>
<li class="dropdown">
<a aria-expanded="false" aria-haspopup="true" class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">Classes</a>
<ul class="dropdown-menu">
<li>
a
</li>
<li>
b
</li>
<li>
c
</li>
<li>
d
</li>
<li>
We
</li>
<li>
r
</li>
<li>
a
</li>
</ul>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
<div class="container">
<div class="HomeMes">
<h1>WELCOME</h1>
</div>
</div>
</div>
The way I could "fix" it is do margin-top: 200px; on the HomeMes class but I know this is bad coding, so I'm trying to find the right way of doing it. If anyone could let me know what I have done wrong that would be excellent. Thanks.
So it should look like this :
Logo Navbar
Welcome message
There you go sir, change your container class to this :
.container {
width:100%;
height:100%;
display:flex;
justify-content:center;
flex-direction: column;
align-items: center;
}
Tested it in chrome and it works, but for some reason it doesn't work in code snippet preview. Hope this helps you. Display:flex helps a lot when trying to horizontally+vertically align elements!