如何将图像用作 html 下拉菜单?
How to use an image as a html dropdown menu?
我正在尝试构建一个 html/css 按钮,当我将鼠标悬停在它上面时,它会显示一个下拉菜单。
不幸的是,它不起作用。
这里是 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>
我认为问题是 css 中嵌套的 类 不正确,试试这个:
.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;
}
我正在尝试构建一个 html/css 按钮,当我将鼠标悬停在它上面时,它会显示一个下拉菜单。
不幸的是,它不起作用。
这里是 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>
我认为问题是 css 中嵌套的 类 不正确,试试这个:
.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;
}