【发布时间】:2020-05-05 11:43:21
【问题描述】:
在https://www.w3schools.com/howto/howto_js_dropdown.asp 的帮助下,我添加了一个带有向下箭头的下拉按钮(图片)。但是,添加向下箭头图像后,按钮的图像区域无法点击?不太清楚这里出了什么问题,按钮仍然可以使用。
HTML:
<html>
<head>
<script>
/* When the user clicks on the button, toggle between hiding and showing the dropdown content */
function dropdownMenu() {
document.getElementById("myDropdown").classList.toggle("show");
}</script>
</head>
<body>
<!-- dropdown feature -->
<div class="dropdown">
<button onclick="dropdownMenu()" class="dropbtn">User
<!--image cant be clicked???-->
<img src="images.png" style="height:8px; width:10px; margin-bottom: 2px; margin-left: 5px;">
</button>
<!-- dropdown content -->
<div id="myDropdown" class="dropdown-content">
<a href="profile.html">Profile</a>
<a href="settings.html">Settings</a>
<a href="#">Logout</a>
</div>
</div>
</body>
</html>
CSS:
.dropbtn {
background-color: white;
color: black;
padding: 10px;
font-size: 14px;
border: none;
cursor: pointer;
position: absolute;
top: -69.5px;
left: 1280px;
border-radius: 4px;
width: 90px;
}
.dropbtn:hover, .dropbtn:focus {
background-color: rgb(218, 218, 218);
}
.dropdown {
position: absolute;
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
top: -20px;
left: 1210px;
background-color: #f1f1f1;
min-width: 164px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 6px;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown a:hover {background-color: #ddd;}
.show {display: block;}
有人可以帮忙找出这里的错误吗?非常感谢!
【问题讨论】:
-
一切对我来说都是正确的。我什至对其进行了测试,对我来说效果很好。codepen.io/oze4/pen/povxBgY
标签: javascript html css image button