Alignment of collapsed menu on hover - html

I have been trying to wrap my head around this issue for over an hour now and can't seem to fix.
When my nav menu collapses and I hover mouse over the SHOP item in menu, it moves the SHOP element to the left. When I mouse away, it goes back to middle position. SHOP should stay in line with the other two menus (NOT move left)
I have tried adjusting the dropdown-menu class as well as CSS for dropdown but still no fix.
Any push in right direction is appreciated. Thanks
HTML:
<div class="collapse navbar-collapse nav-layout" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index">HOME</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle"dropdown" aria-haspopup="true" aria-expanded"false">SHOP</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="products">Tealights</a>
<a class="dropdown-item" href="products">Wax-Melts<span class="sr-only">(current)</span></a>
<a class="dropdown-item" href="products">Medium Candle</a>
<a class="dropdown-item" href="products">Large Candle</a>
<a class="dropdown-item" href="products">X-Large Candle</a>
</div>
</li>
<li>
<a class="nav-link" href="contact">CONTACT</a>
</li>
</ul>
</div>
</nav>
CSS:
.narbar-default .navbar-nav > li.dropdown:hover > a,
.narbar-default .navbar-nav > li.dropdown:hover > a:hover,
.narbar-default .navbar-nav > li.dropdown:hover > a:focus, {
color: rgb(100, 100, 100);
}
.dropdown:hover > .dropdown-menu {
display: block;
background-color: #909090;
}
What displays on screen when hover over SHOP dropdown

You need to add position:absolute to teh dropdown-menu selector. Try this code.
.dropdown {
position: relative;
}
.dropdown > .dropdown-menu {
position: absolute;
left: 0;
top: 100%;
z-index: 2;
}

Related

How to change border color of nav-tab?

I'm having trouble changing the border color for Tab 2 (see below). For Tab 1, the color changes from the default light gray color.
My custom CSS is placed after the bootstrap 5 CSS so it should be overwriting my changes without issue. What am I doing wrong here?
CSS
.nav-tabs {
border-color: black;
}
.nav-tabs > li > a {
border-color: red;
}
.nav-tabs > li > a:hover {
border-color: blue;
}
.nav-tabs > li.active > a {
border-color: green;
}
HTML
<ul class="nav nav-tabs mb-5">
<li class="nav-item active">
<a class="nav-link" href="#">Tab 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Tab 2</a>
</li>
</ul>
There are a few problems...
The active class doesn't automatically change using just HTML markup. Use the Tabs javascript component. For example data-bs-toggle="tab"...
<ul class="nav nav-tabs mb-5">
<li class="nav-item">
<a class="nav-link active" href="#t1" data-bs-toggle="tab">Tab 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#t2" data-bs-toggle="tab">Tab 2</a>
</li>
</ul>
Secondly, the active class goes on the nav-link not the nav-item. So the CSS selector would be...
.nav-tabs > li > .nav-link.active {
border-color: green;
}
https://codeply.com/p/EtmicwumKC

Cannot make Bootstrap navbar transparent

I have been trying to make my navbar transparent but so far nothing has worked for me. Can someone teach me how to do it? I assume it has something to do with the space that it is taking up in regards to the body content, but I am not sure what can be done as I have already tried reversing the div tags to be outside of the body.
This is my desired result :
Fiddle : https://jsfiddle.net/zr1qh780/
My HTML :
<body>
<div id="container">
<!-- Navigation menu -->
<header>
<nav class="my-nav navbar navbar-light navbar-expand-lg">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-
target="#navbarsExample08" aria-controls="navbarsExample08" aria-expanded="false" aria-
label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-md-center" id="navbarsExample08">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="index.html" id="dropdown08" data-toggle="dropdown" aria-
haspopup="true" aria-expanded="false">ACTIVITÉS</a>
<div class="dropdown-menu" aria-labelledby="dropdown08">
<a class="dropdown-item" href="rafting.html">Rafting</a>
<a class="dropdown-item" href="canyoning.html">Canyoning</a>
<a class="dropdown-item" href="saut-parachute.html">Saut en parachute</a>
<a class="dropdown-item" href="soufflerie.html">Simulation de chute libre</a>
<a class="dropdown-item" href="saut-elastique.html">Saut à l’élastique</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">OFFRES</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ÉVÉNEMENTS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">À PROPOS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ESPACE HANDICAP</a>
</li>
<li class="nav-item">
<a class="nav-link contact" href="contact.html">CONTACT</a>
</li>
</ul>
</div>
<div class="hamburger">
<span style="font-size:30px;cursor:pointer;color: white;" onclick="openNav()">☰</span>
</div>
</nav>
</header>
<div id="myNav" class="overlay">
×
<div class="bar overlay-content">
ACTIVITÉS
OFFRES
ÉVÉNEMENTS
À PROPOS
ESPACE HANDICAP
CONTACT
</div>
</div>
My CSS:
.logo {
margin-right:5px;
}
.my-nav{
display: flex;
align-items: center;
justify-content: space-around;
padding: 8px;
}
.navbar-light .navbar-nav .nav-link {
color: white;
}
.navbar-nav > li {
padding-left:25px;
padding-right:45px;
float:none;
display:table-cell;
text-align:center;
font-size: 15px;
font-weight: 500;
}
.navbar-light .navbar-nav .nav-link:focus, .navbar-light .navbar-nav .nav-link:hover {
color: #fc3218;
}
.nav-link:active {
color: #fc3218;
}
.navbar {
background: grey
}
.dropdown-menu {
color: white;
background-color: #fc3218;
}
.dropdown-item {
color: white;
font-size: 14px;
}
.navbar-collapse {
flex-grow: 0.3;
}
Have you tried something like this?
navbar{
background-color: transparent;
}
If that doesn't work, add !important to break the predefined bootstrap styles
Set the opacity of the container for nav bar to 0.
Note: Place the elements of nav bar in different div otherwise the text in nav bar will also get effected.

Hover menu disappear too fast

I got a problem, I do not know what is the problem with the hover menu but it disappears too fast
<div class="dropdown">
<li class="nav-item log-main">
Member
<ul class=" dropdown-menu log">
<li>Sign up</li>
<li>Log in</li>
</ul>
</li>
</div>
css:
.navbar .nav-item ul.log{
display: none;
list-style-type:none;
}
.navbar .dropdown-menu:hover ul.log{
display: block;
}
.log a{
color:var(--main-text-color);
font-family:var(--main-text-font);
font-size: 24px;
}
You need to use :hover pseudo class on .log-main:hover to show the next ul which will be .dropdown-menu
Live Demo:
.navbar .nav-item ul.log {
display: none;
list-style-type: none;
}
.log-main:hover .dropdown-menu {
display: block;
margin-top: 0;
}
.log a {
color: var(--main-text-color);
font-family: var(--main-text-font);
font-size: 24px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="dropdown">
<li class="nav-item log-main">
Member
<ul class="dropdown-menu log">
<li>Sign up</li>
<li>Log in</li>
</ul>
</li>
</div>
You need to add hover to the element that is visible and the dropdown that is hidden.
.dropdown:hover .dropdown-menu,
.dropdown .dropdown-menu:hover{
display: block;
position: absolute;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</nav>

Select an element from multilevel ul li structure

I have a ul li structure that looks like as in the code below.
I want to display just the first level of drop-down on hover. Now, since the <ul> has "drop-down menu" in various places withing the same <ul> tag, it displays all the items that are under this class. One way is to add a parent class either adding in HTML or dynamically by writing some script.
Is there a way we could access this directly using CSS alone ?
.nav-item:hover .dropdown-menu ul { should exclude all the dropdown-menu class where there is also a submenu class - something like this
}
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="#">
Item 1
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Item 2
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Item 3
</a>
<ul class="submenu dropdown-menu">
<li>
<a class="dropdown-item" href="#">
Second Level item1
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Second Level item2
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Second Level item3
</a>
<ul class="submenu dropdown-menu">
<li>
<a class="dropdown-item" href="#">
Third Level item1
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Third Level item2
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Third Level item3
</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a class="dropdown-item" href="#">
Item 4
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Item 5
</a>
<ul class="submenu dropdown-menu">
<li>
<a class="dropdown-item" href="#">
Second Level item1
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Second Level item2
</a>
</li>
</ul>
</li>
</ul>
The code runs perfectly in the real application by adding a specific class.
Add > to select direct child .navbar .nav-item:hover > .dropdown-menu
.navbar .nav-item:hover > .dropdown-menu{
display: block;
border-radius: 0;
background-color: #233d00;
position: absolute;
}
To active submenu when hover dropdown-menu
.dropdown-menu li:hover>.submenu{
display: block;
background-color: #233d00;
}
Try this codepen Demo
nav {
vertical-align: middle;
text-align: center;
font-size: 12px;
background: #233d00 0% 0% no-repeat padding-box;
}
li:hover{background: #647e8f;}
#media all and (min-width: 992px) {
.navbar .nav-item:hover .nav-link {color: #fff;}
.navbar .nav-item:hover>.dropdown-menu{
display: block;
border-radius: 0;
background-color: #233d00;
position: absolute;
}
.dropdown-item{color: #fff !important;}
.dropdown-menu li{position: relative;}
.nav-item .submenu{
display: none;
position: absolute;
left:100%;
top:-1px;
}
.dropdown-menu li:hover{ background-color: #f1f1f1 }
.dropdown-menu li:hover>.submenu{
display: block;
background-color: #233d00;
}
.dropdown-submenu li:hover > .dropdown-submenu{
display: block;
background-color: #233d00;
}
ul.dropdown-submenu {
list-style-type: '';
padding: 0;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" />
<body>
<nav class="navbar py-0 navbar-expand-lg navbar-dark" id="second-navbar">
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#main_nav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="main_nav">
<ul class="navbar-nav nav-fill w-100 nav-pills">
<li class="nav-item active"><a class="nav-link" href="#">First Level Item 1</a></li>
<li class="nav-item dropdown">
<a class="nav-link" href="#" data-toggle="dropdown">First Level Item 2</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">First Level Sub Item 1</a></li>
<li><a class="dropdown-item" href="#">First Level Sub Item 2</a></li>
<li><a class="dropdown-item" href="#">First Level Sub Item 3</a>
<ul class="submenu dropdown-menu">
<li><a class="dropdown-item" href="#">Second Level item1</a></li>
<li><a class="dropdown-item" href="#">Second Level item1</a></li>
<li><a class="dropdown-item" href="#">Second Level item1</a>
<ul class="submenu dropdown-menu">
<li><a class="dropdown-item" href="#">Third Level item1</a></li>
<li><a class="dropdown-item" href="#">Third Level item2</a></li>
<li><a class="dropdown-item" href="#">Third Level item3</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link" href="#" data-toggle="dropdown">First Level Item 3</a>
<ul class="submenu dropdown-menu">
<li><a class="dropdown-item" href="#">Submenu item 1</a></li>
<li><a class="dropdown-item" href="#">Submenu item 2</a></li>
</ul>
</li>
</ul>
</div>
</nav>
Take screen width greater than 992px to view navbar
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</body>
As you are having different level, you must make different css setting:
.navbar li:hover ul{
display: block;
border-radius: 0;
background-color: #233d00;
position: absolute;
}
.navbar li:hover ul li ul{
display: none;
border-radius: 0;
background-color: #233d00;
position: absolute;
}
.navbar li ul li:hover ul{
display: block;
border-radius: 0;
background-color: #233d00;
position: absolute;
}
.navbar li ul li:hover ul li ul{
display: none;
border-radius: 0;
background-color: #233d00;
position: absolute;
}
.navbar li ul li ul li:hover ul{
display: block;
border-radius: 0;
background-color: #233d00;
position: absolute;
}

Bootstrap navtab hover does not cover full tab

I'm using bootstrap nav tab to make the main page tabs.
I made it in a way that when a user hover the mouse over any tab, it changes color. The problem that I'm having right now is that the hover does not cover the entire range of each tab. I looked around webs to solve this issue but I wasn't able to address this issue.
HTML
<header>
<a href="#">
<img src="../static/img/the_logo_original_fixed.jpg" style="width: 140px;height:100px;" class="the_logo">
</a>
<nav class="navbar navbar-light bg-faded">
<ul class="nav nav-tabs" style="border-bottom:0px">
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Support</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</nav>
</header>
CSS
.the_logo{
margin-top: 20px;
margin-bottom: 20px;
}
nav.navbar.navbar-light.bg-faded{
background-color: #3081B7;
}
a{
color: white !important;
font-size: 120%;
}
.nav.nav-tabs > li > a:hover,
.nav.nav-tabs > li > a:active,
.nav.nav-tabs > li > a:focus{
background-color: #5FA6D5 !important;
border: none;
color: #5FA6D5;
}
Try adding the hover functionality to the list item not to the anchor tag because the anchor tag is smaller it only covers the text area.