gpt4 book ai didi

html - 如何停止下拉菜单成为导航栏的一部分?

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

我正在尝试制作一个带有下拉菜单的网站,但它会作为导航栏的一部分展开。

我试过改变显示的类型和位置,但没用

结果是here .

body {
margin: 0px;
font-family: arial;
background-color: rgb(240, 240, 240);
}

li {
list-style: none;
}

/*NAV BAR*/

.navbar {
background-color: white;
display: block;
justify-content: center;
min-width: 1000px;
border-bottom: 1px solid rgb(220, 220, 220);
}

.navbaritems {
display: flex;
justify-content: center;
flex-direction: row;
margin: 0px;
padding: 0px;
}

.navbaritem {
padding: 15px;
}

.navbaritem .text {
text-decoration: none;
font-size: 20px;
color: rgb(10, 80, 150);
}

.navimg {
justify-content: center;
padding-top: 30px;
zoom: 18%;
}

.dropdown {
display: none;
}

.navbaritem:hover {
background-image: linear-gradient(to top, rgba(90, 140, 220, 1), rgba(110, 150, 250, 0.2));
}

.navbaritem:hover .text {
color: white;
}

.navbaritem:hover .dropdown {
display: block;
position: relative;
;
}
<div class="navbar-container">
<nav class="navbar">
<ul class="navbaritems">
<li class="navbaritem"><a class="text" href="index.html">Home</a></li>
<li class="navbaritem"><a class="text" href="about.html">About</a>
<div class="">
<ul class="dropdown">
<li class="droption"><a class="text" href="">About</a></li>
<li class="droption">
<a class="text" href=""></a>
</li>
</ul>
</div>
</li>
</ul>
</nav>
</div>

最佳答案

下面的这些更改只是对部分解决方案的粗略尝试,只是为了让您了解可能有帮助的内容:

.navbaritem {padding: 15px; position: relative; }
.navbaritem:hover .dropdown {
background-color: rgba(90,140,220,1);
display: block;
height: 40px;
left: 0;
padding-left: 15px;
padding-top: 10px;
position: absolute;
top: 53px;
width: 67.5px;
}

重要的是使用绝对定位,这样下拉元素在可见时所占用的大小不会影响父组件的大小。

CSS 的其余部分只是一种临时尝试,旨在使一个下拉元素看起来相当不错——它并不意味着成为获得您想要的布局和样式的通用解决方案的一部分。

https://codepen.io/kshetline/pen/gNNNaN?editors=1100

关于html - 如何停止下拉菜单成为导航栏的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57049913/

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