DAVID
DAVID

Reputation: 92

How to use an image as a html dropdown menu?

I am trying to build a html/css button that when I hover over it, it displays a dropdown.
Unfortunately, it isn't working.

Here is the Code.

.Panel {
  overflow: hidden;
  width: 25%;
  height: 100%;
  color: blue;
  scrollbar-color: black lightgrey;
  scrollbar-width: thin;
  float: left;
}

.Panel a {
  color: black;
  white-space: pre;
  text-decoration: none;
}

body {
  overflow: hidden;
  background: url(../Images/Texture.png) repeat 0 0;
}

.Document {
  pointer-events: auto;
  position: static;
  padding-left: 26%;
  width: 49%;
  height: 100%;
}

.dropbtn {
  padding: 16px;
  font-size: 16px;
  border: none;
  background-image: url("../Images/dropdown.png");
  background-size: 50px 28px;
  background-repeat: no-repeat;
  height: 28px;
  width: 50px;
}

.Panel {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 160px;
  overflow: auto;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {
  background-color: #ddd;
}

.dropbtn:hover {
  background-image: url("../Images/dropdown2.png");
  background-size: 28px 50px;
  background-repeat: no-repeat;
  height: 50px;
  width: 28px;
  margin-left: 30px;
  .dropdown-content {
    display: block;
  }
}
<div class="Panel">
  <button class="dropbtn"></button>
  <div id="myDropdown" class="dropdown-content">
    <br> <br>
    <a href="../" target="_self">   Home</a> <br>
    <a href="" target="_self"> </a> <br>
    <a href=”” target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a><br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a> <br>
    <a href="" target="_self"> </a><br>

  </div>
</div>

Upvotes: 0

Views: 141

Answers (1)

Erica T.
Erica T.

Reputation: 450

I think the problem is the incorrect nested classes in the css, try this instead:

.dropbtn:hover {
background-image: url("../Images/dropdown2.png");
background-size: 28px 50px;
background-repeat: no-repeat;
height: 50px;
width: 28px;
margin-left: 30px;
}
.dropbtn:hover + .dropdown-content {
display: block;
}

Upvotes: 1

Related Questions