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>
Related
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; }
Hello I'm having a problem with my bootstrap dropdown every dropdown has to start where the first nav option is like in the pictures below. If you need some more info just tell me and i will add it to this post.
I've did some research already and I've seen some examples about mega menu stuff but i couldn't get it to work in my project so i started to do it my self.
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<style>
.box {
display: block;
width: 100%;
min-height: 250px;
margin-bottom: 10px;
padding: 5px;
}
.Tilebackground {
background-color: #efefef !important;
width: 200px !important;
height: 145px !important;
margin-right: 20px !important;
}
.Tileheader {
font-family: 'Segoe UI Emoji';
color: #414142;
font-size: 18px;
font-weight: 400;
line-height: 12.926px;
transform: scale(1.259, 1.259);
text-align: center;
margin-top: 20px;
}
.Tilefooter {
font-family: 'Segoe UI';
color: #414142;
font-size: 12px;
font-weight: 200;
line-height: 18px;
margin-top: 10px;
}
.dropdown-toggle::after {
display: none;
}
.mega-menu {
width: 863px !important;
height: auto !important;
background-color: grey;
}
.dropdown-item {
color: white !important;
}
.btn {
box-shadow: none !important;
}
.btn-secondary {
border-color: initial !important;
}
.dropdown:hover>.dropdown-menu {
display: block;
}
.relative {
position: relative;
top: 0;
}
.absolute {
position: absolute;
}
</style>
</head>
<body>
<div class="container-fluid" style="background-color: #787878;">
<div class="row">
<nav class="navbar navbar-expand-lg navbar-dark" style="width: 100%; background-color: #787878; padding-left: 40px; padding-right: 40px;">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#">Over Connect Pro</a></li>
<li class="nav-item"><a class="nav-link" href="#">Referenties</a></li>
<li class="nav-item"><a class="nav-link" href="#">Vacatures</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
</ul>
</div>
</nav>
</div>
</div>
<div class="container-fluid" style="background-color: #FFF; border-bottom: 1px solid #787878;">
<div class="row">
<nav class="navbar navbar-expand-lg navbar" style="width: 100%; padding: 20px; padding-left: 40px; padding-right: 40px;">
<a class="navbar-brand" href="#" style="color: #000"><img src="images/toplogo.png" alt="Connect Pro"></a>
<button class="navbar-toggler" style="color: #000" type="button" data-toggle="collapse" data-target="#navbarSupported">
<span class="navbar-toggler-icon" style="color: #000" ></span>
</button>
<div class="collapse navbar-collapse relative" id="navbarSupported">
<ul class="navbar-nav ml-auto">
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle Tilebackground" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<p class="Tileheader">Onze aanpak</p>
<p class="Tilefooter">PROACTIEVE ICT <br> ONDERSTEUNING <br> VOOR BEDRIJVEN</p>
</button>
<div class="dropdown-menu mega-menu w-100 absolute container" aria-labelledby="dropdownMenuButton">
<div class="row w-100 d-flex">
<div class="col">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">And an another action</a>
<a class="dropdown-item" href="#">one more action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
<div class="col">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">And an another action</a>
<a class="dropdown-item" href="#">one more action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
<div class="col">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">And an another action</a>
<a class="dropdown-item" href="#">one more action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</div>
</div>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle Tilebackground" type="button" id="dropdownMenuButton2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<p class="Tileheader">Oplossingen</p>
<p class="Tilefooter">LOKALE INFRASTRUCTUUR,<br> CLOUD, VOIP, SECURITY, <br>TICKETING, MONITORING,...</p>
</button>
<div class="dropdown-menu mega-menu w-100 absolute container" aria-labelledby="dropdownMenuButton2">
<div class="row w-100">
<div class="col">
<a class="dropdown-item" href="#">Action2</a>
<a class="dropdown-item" href="#">Another action2</a>
<a class="dropdown-item" href="#">Something else here2</a>
</div>
<div class="col">
<a class="dropdown-item" href="#">Action2</a>
<a class="dropdown-item" href="#">Another action2</a>
<a class="dropdown-item" href="#">Something else here2</a>
</div>
<div class="col">
<a class="dropdown-item" href="#">Action2</a>
<a class="dropdown-item" href="#">Another action2</a>
<a class="dropdown-item" href="#">Something else here2</a>
</div>
</div>
</div>
</div>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle Tilebackground" type="button" id="dropdownMenuButton3" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<p class="Tileheader">Producten</p>
<p class="Tilefooter">FIREWALLS, PRINTERS, <br> NOTEBOOKS, SIP PHONES, <br>EN MEER</p>
</button>
<div class="dropdown-menu mega-menu w-100 absolute container" aria-labelledby="dropdownMenuButton3">
<div class="row w-100">
<div class="col">
<a class="dropdown-item" href="#">Action3</a>
<a class="dropdown-item" href="#">Another action3</a>
<a class="dropdown-item" href="#">Something else here3</a>
</div>
<div class="col">
<a class="dropdown-item" href="#">Action3</a>
<a class="dropdown-item" href="#">Another action3</a>
<a class="dropdown-item" href="#">Something else here3</a>
</div>
<div class="col">
<a class="dropdown-item" href="#">Action3</a>
<a class="dropdown-item" href="#">Another action3</a>
<a class="dropdown-item" href="#">Something else here3</a>
</div>
</div>
</div>
</div>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle Tilebackground" type="button" id="dropdownMenuButton4" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<p class="Tileheader">Partners</p>
<p class="Tilefooter">ONS NETWERK VAN <br> LOKALE IT PARTNERS <br>OVER HEEL BELGIË</p>
</button>
<div class="dropdown-menu dropdown-menu-right mega-menu container" aria-labelledby="dropdownMenuButton4">
<div class="row">
<div class="col">
<a class="dropdown-item" href="#">Action4</a>
<a class="dropdown-item" href="#">Another action4</a>
<a class="dropdown-item" href="#">Something else here4</a>
</div>
<div class="col">
<a class="dropdown-item" href="#">Action4</a>
<a class="dropdown-item" href="#">Another action4</a>
<a class="dropdown-item" href="#">Something else here4</a>
</div>
<div class="col">
<a class="dropdown-item" href="#">Action4</a>
<a class="dropdown-item" href="#">Another action4</a>
<a class="dropdown-item" href="#">Something else here4</a>
</div>
</div>
</div>
</div>
</ul>
</div>
</nav>
</div>
</div>
A quick, slightly hacky fix, but one the only way I can think of using bootstrap.
As the first box dropdown is working fine this one is good. However for the other 3 boxes I have given them each a class (I used dd-2, dd-3 and dd-4).
All I did was set the position: absolute; left: figure to minus the width of the button (220px)
(added) CSS:
.dd-2 //dropdown box 2 {
left: -220px;
}
.dd-3 //dropdown box 3 {
left: -440px;
}
.dd-4 //dropdown box 4 {
left: -660px;
}
here is my codepen showing how this was used (sorry I split your code up for my codepen) : https://codepen.io/CodeBoyCode/pen/Pyyvgw
Let me know if this is what you were looking for
Thanks
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;
}
I am making a navbar with multi level drop down menu. I want to make the height of drop-down menu same as the height of sub-menu.
Like This:
When the sub-menu is hidden, the drop-down menu will return the original size.
Like This:
Here is my code
.dropdown-submenu a::after {
transform: rotate(-90deg);
right: 3px;
top: 40%;
}
.dropdown-submenu:hover .dropdown-menu,
.dropdown-submenu:focus .dropdown-menu {
display: block;
margin-top: -1px;
margin-left: -1px;
top: 0px;
left: 100%;
min-height: 100%;
}
.dropdown-menu {
min-height: 200%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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-sm navbar-light ">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
</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="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu " aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Action</a></li>
<li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle" data-toggle="dropdown" href="#">Something else here</a>
<div class="dropdown-menu top">
<a class="dropdown-item" href="#">A</a>
<a class="dropdown-item" href="#">b</a>
<a class="dropdown-item" href="#">b</a>
<a class="dropdown-item" href="#">b</a>
<a class="dropdown-item" href="#">b</a> <a class="dropdown-item" href="#">b</a> <a class="dropdown-item" href="#">b</a>
</div>
</li>
</ul>
</li>
</ul>
</nav>
How can i do this?
Is this what you wanted? I added a class .add-to-ul and a class .add-to-dropdown-div at, well the name says it. And gave it some styles.
Also I added an ID to the nav so I can style the bootstrap elements easier.
.dropdown-submenu a::after {
transform: rotate(-90deg);
right: 3px;
top: 40%;
}
.dropdown-submenu:hover .dropdown-menu,
.dropdown-submenu:focus .dropdown-menu {
display: block;
margin-top: -1px;
margin-left: -1px;
top: 0px;
left: 100%;
min-height: 100%;
}
.dropdown-menu {
min-height: 200%;
}
#bootstrap-edits .add-to-ul{
position: relative;
width: 100%;
top: 0;
}
#bootstrap-edits .add-to-dropdown-div{
min-height: 100%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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-sm navbar-light " id="bootstrap-edits">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
</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="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu add-to-ul" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Action</a></li>
<li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle" data-toggle="dropdown" href="#">Something else here</a>
<div class="dropdown-menu top add-to-dropdown-div">
<a class="dropdown-item" href="#">A</a>
<a class="dropdown-item" href="#">b</a>
<a class="dropdown-item" href="#">b</a>
<a class="dropdown-item" href="#">b</a>
<a class="dropdown-item" href="#">b</a> <a class="dropdown-item" href="#">b</a> <a class="dropdown-item" href="#">b</a>
</div>
</li>
</ul>
</li>
</ul>
</nav>
<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.