<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" 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>
I've wrote this code to create a dropdown with bootstrap (very easy) now I'm trying to remove the background when I hover over the item inside the dropdown but somehow they always stay white.
This is the css
.dropdown-menu{
background-color: transparent;
border: transparent;
border: none;
}
.dropdown-menu .dropdown-item > li > a:hover {
background-image: none;
background-color: #000;
}
add .bg-transparent to the .dropdown-item elements. Done.
easiest way to do this is take a new class inside drop down-menu and apply css
check this fiddle, updated fiddle https://jsfiddle.net/rb87gwzj/4/ or this snippet
.dropdown-menu{
background-color: transparent;
border: transparent;
border: none;
}
.dropdown-menu .dropdown-item > li > a:hover {
background-image: none;
background-color: #000!important;
}
.navbar {
background: none;
}
.dropdown-content a:hover {
background-color: transparent;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="index.html">
<img src="images/logo.png" width="30" height="30" class="d-inline-block align-top" alt="">
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Projects
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink" >
<div class="dropdown-content">
<a class="dropdown-item" href="#html">HTML5/CSS</a>
<a class="dropdown-item" href="#python">Python</a>
<a class="dropdown-item" href="#php">PHP</a>
<a class="dropdown-item" href="#java">Java</a>
<a class="dropdown-item" href="#csharp">C#</a>
</div>
</div>
</li>
</ul>
</div>
</nav>
you applied CSS on dropdown-menu .dropdown-item > li > a:hover but you are structure is not same, you have no dropdown-item inside drop down-menu, no li inside dropdown-item, tell me if you want me explain more
Use
background-color: transparent !important;
or
Use same color which one is used in default case.
Where you want to change.
Related
I am trying to give the background color to menu toggler icon , when the html page make compact to mobile view. Since the menu back ground color is set to white , if the screen make compact , the menu toggler icon cannot be seen. So I am trying to give color background or to give color to its border.
Here is the code
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark" id="main-nav">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">MyCompany</a>
<button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Privacy">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Privacy">
Our
Project
</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Privacy">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
Then in custom.css file , I given the color, still not working
.custom-toggler.navbar-toggler {
border-color: rgb(255,102,203) !important;
}
Is your css style file imported correctly? I have used your style to be effective, you can refer to my side, it may be useful to you.
This is an example I obtained from the official, adding bootstrap5 and custom css styles that I introduced:
<nav class="navbar navbar-expand-lg navbar-custom navbar-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
<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>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-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>
</ul>
</div>
</div>
</nav>
#section Scripts{
<script src="~/bootstrap/js/bootstrap.js"></script>
<link href="~/bootstrap/css/custom.css" rel="stylesheet" />
}
Custom css style:
.navbar-custom {
background-color: #4433cc;
}
/* change the brand and text color */
.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
color: #ffcc00;
}
/* change the link color */
.navbar-custom .navbar-nav .nav-link {
color: #ffbb00;
}
/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:focus .nav-link,
.navbar-custom .nav-item:hover .nav-link {
color: pink;
}
/* for dropdowns only */
.navbar-custom .navbar-nav .dropdown-menu {
/* background-color: deepskyblue;*/
border-color: rgb(255,102,203) !important;
}
/* dropdown item text color */
.navbar-custom .navbar-nav .dropdown-item {
color: #000000;
}
/* dropdown item hover or focus */
.navbar-custom .navbar-nav .dropdown-item:hover,
.navbar-custom .navbar-nav .dropdown-item:focus {
color: #eeeeee;
background-color: red;
}
Here I put your border-color: rgb(255,102,203) !important; style on .navbar-custom .navbar-nav .dropdown-menu, the results are as follows:
Nav is changing site width. I don't know why's that.
I thought that's because margins or padding, but couldn't find any way to fix the problem.
I came to conclusion that is cousing problems, but I don't know why's that.
Please help!
HTML code:
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">IT SPECIALIST</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#menu" aria-controls="menu" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="menu">
<ul class="navbar-nav ms-auto">
<li class="nav-item active">
<a class="nav-link" id="active" href="#">GŁÓWNA</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="nav-link" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
O NAS
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Zespół</a>
<a class="dropdown-item" href="#">Partnerzy</a>
<a class="dropdown-item" href="#">Facebook Fanpage</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="nav-link" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
OFERTA
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Odzyskiwanie Danych</a>
<a class="dropdown-item" href="#">Wsparcie dla twojej firmy</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" id="nav-link" href="#">USŁUGI DLA FIRM I OSÓB PRYWATNYCH</a>
</li>
<li class="nav-item">
<a class="nav-link" id="nav-link" href="#">DLACZEGO MY</a>
</li>
<li class="nav-item">
<a class="nav-link" id="nav-link" href="#">ZGŁOŚ AWARIĘ</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="col-md-2"></div>
</div>
I deleted whole css code, and nothing changed, but in case you need it here it is:
CSS code:
body {
margin: none;
padding: none;
}
.navbar .navbar-brand {
margin-left: 1vw;
}
.navbar button {
margin-right: 1vw;
}
.navbar .dropdown-item:hover, .navbar #nav-link:hover, .navbar #active {
background-color: #5394dd;
color: white;
}
.navbar .nav-item {
margin-left: 0.5vw;
}
.navbar .nav-item:last-child {
margin-right: 1vw;
}
Edit 1:
row is cousing the problem, while using nav, without any rows, and columns, navigation is taking whole site width, nothing more.
So, is there any other way, to center site, like this?
Remove all col's from around the Navbar and add a container instead.
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<!--Your nav content here-->
</nav>
</div>
I'm not sure exactly how it is destroying the site's width but try this adding this to your styling:
*{
margin: 0;
padding: 0;
}
I am making a project and I added a dropdown menu on navbar and I don't know why that it seems to push the HTML down when toggled. I tried making its position absolute and top 100% but it didn't work, I am using bootstrap, please help
Here is the main HTML
body{
background-color: #0b0c10!important;
}
nav{
background-color: #0b0c10!important;
color: turquoise;
text-decoration: none;
}
nav a{
color: turquoise;
text-decoration: none;
font-family: 'Lato', sclear-serif;
}
nav a:hover{
color: white;
text-decoration: none;
transition-duration: 1s;
}
.navbar-nav{
margin-right: 80px;
text-align: center!important;
}
.navbar-brand{
font-family: 'Lobster', cursive;
font-size: 30px!important;
margin-left: 30px;
}
<nav class="navbar navbar-expand-lg ">
<a class="navbar-brand" href="#">Calcify</a>
</button>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More Calculator
</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>
</ul>
</nav>
I think you have to add jquery.min.js, popper.min.js, and bootstrap.min.js.
In the introduction of Bootstrap it states which imports you need to add. https://getbootstrap.com/docs/4.0/getting-started/introduction/#quick-start
You have to add some scripts in order to get bootstrap fully working. It's important that you include them in this exact order. Popper.js is one of them:
<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.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
Example
<nav class="navbar navbar-expand-lg ">
<a class="navbar-brand" href="#">Calcify</a>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More Calculator
</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>
</ul></nav>
.navbar{
align-items: stretch!important;
}
.navbar-nav .dropdown-menu {
position: absolute;
}
for your dropdown items list use
position:absolute;
z-index:5;
this worked for me
body{
background-color: #0b0c10!important;
}
nav{
background-color: #0b0c10!important;
color: turquoise;
text-decoration: none;
}
nav a{
color: turquoise;
text-decoration: none;
font-family: 'Lato', sclear-serif;
}
nav a:hover{
color: white;
text-decoration: none;
transition-duration: 1s;
}
.navbar-nav{
margin-right: 80px;
text-align: center!important;
}
.navbar-brand{
font-family: 'Lobster', cursive;
font-size: 30px!important;
margin-left: 30px;
}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Calcify</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" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<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 Calculator
</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>
</ul>
</div>
</nav>
I have a full-width Bootstrap dropdown menu that is not working properly as it has a lot of space between the button and the menu.
So far I am only using CSS for this, no javascript. Here´s the code:
HTML:
<nav class="p-4 navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="http://lorempixel.com/30/30/abstract" width="30" height="30" class="d-inline-block align-top" alt="">
Shopstrap
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<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="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<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
<i class="fas fa-angle-up"></i>
</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>
<li class="nav-item dropdown catalog">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Catalog
<i class="fas fa-angle-up"></i>
</a>
<div class="dropdown-menu catalog-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>
</div>
</nav>
CSS:
.navbar-default .navbar-nav > li.dropdown:hover > a,
.navbar-default .navbar-nav > li.dropdown:hover > a:hover,
.navbar-default .navbar-nav > li.dropdown:hover > a:focus {
background-color: rgb(231, 231, 231);
color: rgb(85, 85, 85);
}
li.dropdown:hover > .dropdown-menu {
display: block;
}
.navbar .dropdown.catalog {
position: static;
float: none;
}
.navbar .dropdown .dropdown-menu.catalog-menu{
width: 100%;
}
Fiddle:
https://jsfiddle.net/m4Lxugea/1/
I hope any of you can help me with this. I was thinking in maybe I can´t do this purely CSS but I need to add javascript for the hovering.
Alejandro.
The key CSS for you is:
li.dropdown:hover > .dropdown-menu {
display: block;
}
Which means that: while you're hovering over the 'Catalog' link in the navigation (on desktop), show the child .dropdown-menu and as soon as you hover away, the .dropdown-menu goes to its default state of display:none;
With JS you can add a class which makes sure that the .dropdown-menu stays open unless you click somewhere else to undo this
Here is solution: Bootstrap adds margin-top for each dropdown-menu class.
Make it 0px;
Bootstrap has padding on navbar class, Also make override it to 0px;
Here is working example https://bootstrap-menu.com/detail-megamenu.html
navbar{ padding-top: 0; padding-bottom: 0; }
navbar .has-megamenu{position:static!important;}
navbar .megamenu{left:0; right:0; width:100%; padding:20px; }
navbar .nav-link{ padding-top:1rem; padding-bottom:1rem; }
I have a menu with a dropdown in it. When I click the dropdown, the child menu is a color. I'm trying to maintain that same color (which is in the hover state) in the parent item, after the menu is clicked. Currently, when I click the dropdown and then mouse away from the parent, it changes back to the original menu color (pink).
Best to open the snippet in full page to see what I'm referring to.
.dropdown-menu {
border: none;
border-radius: 0;
margin: 0;
}
.dropdown-item:hover {
background-color: #0091c7;
}
.nav-link.dropdown-toggle:hover {
background-color: #00aeef;
}
.nav-link > li.dropdown-toggle.active > a,
.nav-link > li.dropdown-toggle.active > a:focus,
.nav-link > li.dropdown-toggle.active > a:hover {
background-color: #00aeef;
color: #ffffff;
}
.bg-pink {
background-color: #d60c8c;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container p-5">
<div class="row">
<div class="col-sm-12">
<!-- HTML here -->
<div class="container-fluid bg-pink">
<div class="container">
<div class="row">
<div class="col-lg-12">
<nav class="navbar navbar-expand-lg navbar-light bg-pink">
<a class="navbar-brand" href="#">
<i class="fa fa-home fa-2x"></i>
</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" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown Parent
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #00aeef;">
<a class="dropdown-item" href="#">Action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Action Action</a>
<a class="dropdown-item" href="#">Action Action</a>
<a class="dropdown-item" href="#">Action Action</a>
<a class="dropdown-item" href="#">Action Action Action</a>
</div>
</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>
</ul>
</div>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
When the dropdown is clicked, the show class is added to its parent li.
I added
li.show > #navbarDropdown,
to your css here:
li.show > #navbarDropdown,
.nav-link > li.dropdown-toggle.active > a,
.nav-link > li.dropdown-toggle.active > a:focus,
.nav-link > li.dropdown-toggle.active > a:hover {
background-color: #00aeef;
color: #ffffff;
}