gpt4 book ai didi

html - 导航栏中的 Css 下拉按钮

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:35 25 4
gpt4 key购买 nike

好吧,我正在尝试学习 CSS,并且正在尝试在导航栏中插入下拉按钮。

发生的事情是,当我将鼠标悬停在按钮上时,整个导航栏都会展开,而不仅仅是按钮的内容。我究竟做错了什么?谢谢!

ul {
list-style-type: none;
margin-left:8%;
margin-right: 8%;
padding-left: 0;
padding-right: 0;
overflow: hidden;
background-color: #f3f3f3;
}

.right{
float: right;
}


li a {
float: left;
display: block;
color: #6f6f6f;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover {
background-color: #e0e0e0;
}

p {
color: red;
margin-left: 8%;
margin-right: 8%;
}

body{
font-family:Arial;
background-color:#f9f9f9;
}

.dropbtn {
background-color: #f3f3f3;
color: #6f6f6f;
padding: 14px 16px;
font-size: 16px;
border: none;
cursor: pointer;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
right: 0;
display: none;
position: relative;
background-color: #f9f9f9;
min-width: 10px;
}

/* Links inside the dropdown */
.dropdown-content a {
right: 0;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #e0e0e0}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
right:0;
}

/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #e0e0e0;
}
<ul>
<li><a href="/"><img src="../../static/image/logoRect.png" width="25"> </a></li>
<li><a href="/movies">Movies</a></li>
<li><a class="right" href="">Search</a></li>
<div class="right">
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Links 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</div>
<li><a class="right" href="#about">Explore</a></li>
</ul>

最佳答案

您必须指定一个高度并移除隐藏的溢出。

ul {
list-style-type: none;
margin-left:8%;
margin-right: 8%;
padding-left: 0;
padding-right: 0;
// overflow: hidden; <---remove
height: 48px; // <---add
background-color: #f3f3f3;
}

如果你不这样做,ul 默认为好像它有:

height: auto;

相关fiddle

关于html - 导航栏中的 Css 下拉按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36730822/

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