gpt4 book ai didi

html - 如何让导航菜单在主 div 上溢出

转载 作者:行者123 更新时间:2023-11-28 02:13:27 24 4
gpt4 key购买 nike

我创建了带有水平菜单和导航子菜单的基本 html 页面。我想让子菜单打开并在主区域可用,但导航会调整大小,将主菜单向下移动。我尝试了溢出选项,但没有成功(没有效果)。我尝试了主菜单的绝对位置,但随后无法使用子菜单(当我将光标移动到子菜单时它消失了),尽管它显示如我所愿。下面的代码。感谢您的回答。

header {
background-color: rgb(200, 200, 200);
border-radius: 1px;
color: white;
text-align: center;
padding: 1px;
width: 1480px;
height: 70px;
}

nav.horizontal {
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, .15);
text-align: center;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
width: 1480px;
height: 50px;
resize: none;
}

main {
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, .15);
overflow: hidden;
text-align: center;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
width: 1480px;
height: 600px;
}

nav.horizontal>li {
list-style-type: none;
float: left;
}

nav.horizontal>li>ul {
list-style-type: none;
display: none;
margin: 0;
padding: 0;
}

nav.horizontal li:hover>ul {
display: block;
}

nav.horizontal>li>ul>a {
background-color: rgb(255, 255, 0);
background-image: -webkit-linear-gradient(150deg, rgb(255, 255, 0), rgb(255, 255, 0));
background-image: -moz-linear-gradient(150deg, rgbrgb(255, 255, 0), rgb(255, 255, 0));
background-image: -o-linear-gradient(150deg, rgb(255, 255, 0), rgb(255, 255, 0));
background-image: linear-gradient(150deg, rgb(255, 255, 0), rgb(255, 255, 0));
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1), 0 1px 1px rgba(0, 0, 0, .1);
color: rgb(0, 0, 0);
display: block;
font-size: .65rem;
width: 180px;
height: 30px;
letter-spacing: .1rem;
line-height: 30px;
text-shadow: 0 1px 1px rgba(0, 0, 0, .1);
text-transform: uppercase;
transition: all .1s ease;
text-decoration: none;
cursor: pointer;
}

nav.horizontal>li>a {
background-color: rgb(255, 255, 5);
background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(255, 255, 5));
background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(255, 255, 5));
background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(255, 255, 5));
background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(255, 255, 5));
border-bottom: 1px solid rgba(255, 255, 255, .1);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1), 0 1px 1px rgba(0, 0, 0, .1);
color: rgb(255, 255, 255);
display: block;
font-size: .85rem;
font-weight: 500;
width: 211px;
height: 50px;
letter-spacing: .1rem;
line-height: 50px;
text-shadow: 0 1px 1px rgba(0, 0, 0, .1);
text-transform: uppercase;
transition: all .1s ease;
text-decoration: none;
}

nav.horizontal>li>a:hover {
background-color: rgb(114, 51, 98);
background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
cursor: pointer;
}
<body>
<header>Title</header>
<nav class="horizontal">
<li>
<a href="#"> Menu </a>
<ul>
<a href="#">First</a>
<a href="#">Second</a>
<a href="#">Third</a>
<a href="#">Fourth</a>
</ul>
</li>
</nav>
<main>
</main>
<footer>
</footer>
</body>

最佳答案

尝试添加到您的 nav.horizo​​ntal > li > ul (subnav)

position: absolute;

注意安全并始终使用 ul & li:

<ul>
<li></li>
</ul>

您可以随时检查您的标记 here (https://validator.w3.org/)

关于html - 如何让导航菜单在主 div 上溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48619277/

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