我有四个下拉按钮,如下所示:
我试着勾勒出按钮,我注意到它们甚至没有。
我无法使它们均匀,我尝试使用display: inline-block;
,但这似乎无法解决问题。难道我做错了什么?还是我缺少一些代码?或者甚至可能是因为JavaScript?
这是我的代码:
function myFunction() {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
this.event.target.nextElementSibling.classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function (event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
/* Dropdown Button */
.dropbtn {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
width: 180px;
height: 50px;
text-align: center;
line-height: 1.1em;
font-size: 1.1em;
font-family: Questrial;
}
/* Dropdown button on hover & focus */
.dropbtn:hover,
.dropbtn:focus {
background-color: #3e8e41;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
font-family: Questrial;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 5px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #3B3B3B;
color: #fff;
}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {
display: block;
}
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Add Equipment</button>
<div class="dropdown-content">
<a href="registeravrorups.php">Add AVR / UPS</a>
<a href="registercpu.php">Add CPU</a>
</div>
</div>
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Add Spare Equipment</button>
<div class="dropdown-content">
<a href="registeravrorupsspare.php">Add Spare AVR / UPS</a>
<a href="registercpuspare.php">Add Spare CPU</a>
</div>
</div>
<br>
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Deployed Equipment</button>
<div class="dropdown-content">
<a href="viewavrorups.php">Deployed AVR / UPS</a>
<a href="viewcpu.php">Deployed CPU</a>
</div>
</div>
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Spare Equipment</button>
<div class="dropdown-content">
<a href="registeravrorupsspare.php">View Spare AVR / UPS</a>
<a href="viewcpuspare.php">View Spare CPU</a>
</div>
</div>