Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove hover background dropdown bootstrap 4

<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;
}
like image 221
Sander bakker Avatar asked Feb 04 '23 12:02

Sander bakker


2 Answers

add .bg-transparent to the .dropdown-item elements. Done.

like image 109
Aaron Hudon Avatar answered Feb 07 '23 11:02

Aaron Hudon


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
like image 25
this.girish Avatar answered Feb 07 '23 13:02

this.girish