gpt4 book ai didi

html - 下拉菜单无法按我想要的方式工作

转载 作者:行者123 更新时间:2023-11-28 04:25:50 25 4
gpt4 key购买 nike

我正在尝试制作一个菜单,其中包含一个带有下拉菜单的菜单项,但我似乎不太正确。我开始将我现有的菜单栏与一段下拉菜单代码结合起来,我设法在菜单栏中删除了下拉元素,但我不知道如何让菜单栏再次回到顶部并且它的左边仍然有一个空白。我的下拉菜单中还有一个额外的空元素,我不知道如何摆脱它?

谁能帮帮我,我觉得我忽略了什么

.menu-bar {
position: fixed;
width: 100vw;
background-color: #134c95;
color: white;
display: flex;
flex-direction: row;
justify-content: center;
opacity: 0.8;
}

.menu-item {
padding: 10px;
cursor: default;
font-size: 15pt;
margin-left: 15px;
margin-right: 15px;
}

.menu-item:hover,
a:hover {
background-color: white;
cursor: pointer;
color: 234c95;
}

.menu-bar a {
color: white;
}

.menu-bar a:visited {
color: white;
}

.menu-bar a:link,
.menu-bar a:visited {
text-decoration: none;
}


/*
.menu-bar a:hover {
color: #134c95;
}
*/


/* Dropdown Button */

.dropbtn {
background-color: inherit;
color: white;
/* padding: 16px;*/
/* font-size: 16px;*/
border: none;
cursor: pointer;
}


/* The container <div> - needed to position the dropdown content */


/*
.dropdown {
position: fixed;
display: inline-block;
}
*/


/* Dropdown Content (Hidden by Default) */

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


/* Links inside the dropdown */

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


/* Change color of dropdown links on hover */

.dropdown-content a:hover {
background-color: 234c95;
color: white;
}


/* Show the dropdown menu on hover */

.dropdown:hover .dropdown-content {
display: block;
}


/* Change the background color of the dropdown button when the dropdown content is shown */

.dropdown:hover .dropbtn {
background-color: white;
color: #234c95;
}
<div class="menu-bar">
<a href="instructiestest.html">
<div class="menu-item">Welkom</div>
</a>
<a href="instructie2.html">
<div class="menu-item">Aanmelden Portbase</div>
</a>
<a href="instructie3.html">
<div class="menu-item">De App</div>
</a>
<a href="testing.html">
<div class="dropdown">
<button class="dropbtn">
<div class="menu-item">Het team</div>
<div class="dropdown-content">
<a href="http://google.com" target="_blank">Google</a>
<a href="http://facebook.com" target="_blank">Facebook</a>
<a href="http://youtube.com" target="_blank">YouTube</a>
</div>
</button>
</div>
</a>
</div>

最佳答案

dropdown 元素中删除 a 标签,如下所示:

<div class="menu-bar">
<a href="instructiestest.html">
<div class="menu-item">Welkom</div>
</a>
<a href="instructie2.html">
<div class="menu-item">Aanmelden Portbase</div>
</a>
<a href="instructie3.html">
<div class="menu-item">De App</div>
</a>
<div class="dropdown">
<button class="dropbtn">
<div class="menu-item">Het team</div>
<div class="dropdown-content">
<a href="http://google.com" target="_blank">Google</a>
<a href="http://facebook.com" target="_blank">Facebook</a>
<a href="http://youtube.com" target="_blank">YouTube</a>
</div>
</button>
</div>
</div>

另外,您的 .dropdown-content a:hover 规则在您的 background-color 属性中缺少一个 #:

.dropdown-content a:hover {
background-color: #234c95;
color: white;
}

这是一个有效的 Fiddle

关于html - 下拉菜单无法按我想要的方式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41982440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com