gpt4 book ai didi

html - CSS 扩展导航问题

转载 作者:太空宇宙 更新时间:2023-11-03 17:41:41 26 4
gpt4 key购买 nike

我们有一些如何设法推出一个 css 可扩展导航的东西......我面临的问题是你可以通过将鼠标悬停在主页上看到它的扩展,但你也会看到最后一个菜单是空白的......同样,当您看到 Portfolio 鼠标悬停时,您会看到有 3 个菜单,实际上只有 5 个...

最终我想要的是我们提供的子菜单总数可能是 10 或 5 或 3 甚至 2,主菜单应该展开并显示相同的内容。

你能帮忙解决这个问题吗...

HTML代码

<div class="nav">
<div class="menu-item alpha">
<h4><a href="#">User Managment</a></h4>
<ul>
<li><a href="#">View Users</a></li>
<li><a href="#">Edit User</a></li>
</ul>
</div>

<div class="menu-item">
<h4><a href="#">Portfolio</a></h4>
<ul>
<li><a href="#">Web</a></li>
<li><a href="#">Print</a></li>
<li><a href="#">Other</a></li>
<li><a href="#">Other</a></li>
<li><a href="#">Other</a></li>
<li><a href="#">Other</a></li>
</ul>
</div>

<div class="menu-item">
<h4><a href="#">About</a></h4>
<ul>
<li><a href="#">History</a></li>
<li><a href="#">Meet The Owners</a></li>
<li><a href="#">Awards</a></li>
</ul>
</div>

<div class="menu-item">
<h4><a href="#">Contact</a></h4>
<ul>
<li><a href="#">Phone</a></li>
<li><a href="#">Email</a></li>
<li><a href="#">Location</a></li>
</ul>
</div>
</div>

CSS代码如下

 .nav * {
margin: 0px;
padding: 0px;
}

.nav {
font-family: Helvetica, Arial, "Lucida Grande", sans-serif;
font-size: 13px;
line-height: 1.5;
}

.menu-item {
background: #fff;
width: 200px;
}

/*Menu Header Styles*/
.menu-item h4 {
border-bottom: 1px solid rgba(0,0,0,0.3);
border-top: 1px solid rgba(255,255,255,0.2);
color: #fff;
font-size: 15px;
font-weight: 500;
padding: 7px 12px;

/*Gradient*/
background: #a90329; /* Old browsers */
background: -moz-linear-gradient(top, #a90329 0%, #8f0222 44%, #6d0019 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a90329), color-stop(44%,#8f0222), color-stop(100%,#6d0019)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #a90329 0%,#8f0222 44%,#6d0019 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #a90329 0%,#8f0222 44%,#6d0019 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #a90329 0%,#8f0222 44%,#6d0019 100%); /* IE10+ */
background: linear-gradient(top, #a90329 0%,#8f0222 44%,#6d0019 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a90329', endColorstr='#6d0019',GradientType=0 ); /* IE6-9 */
}

.menu-item h4:hover {
background: #cc002c; /* Old browsers */
background: -moz-linear-gradient(top, #cc002c 0%, #6d0019 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#cc002c), color-stop(100%,#6d0019)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #cc002c 0%,#6d0019 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #cc002c 0%,#6d0019 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #cc002c 0%,#6d0019 100%); /* IE10+ */
background: linear-gradient(top, #cc002c 0%,#6d0019 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cc002c', endColorstr='#6d0019',GradientType=0 ); /* IE6-9 */

}

.menu-item h4 a {
color: white;
display: block;
text-decoration: none;
width: 200px;
}

/*ul Styles*/
.menu-item ul {
background: #fff;
font-size: 13px;
line-height: 30px;
height: 0px;
list-style-type: none;
overflow: hidden;
padding: 0px;

/*Animation*/
-webkit-transition: height 2s ease;
-moz-transition: height 1s ease;
-o-transition: height 1s ease;
-ms-transition: height 1s ease;
transition: height 1s ease;
}


.menu-item:hover ul {
height: 93px;

}

.menu-item ul a {
margin-left: 20px;
text-decoration: none;
color: #aaa;
display: block;
width: 200px;
}

/*li Styles*/
.menu-item li {
border-bottom: 1px solid #eee;
}

.menu-item li:hover {
background: #eee;
}

/*First Item Styles*/
.alpha p {
padding: 8px 12px;
color: #aaa;
}

.alpha p a {
color: #aaa;
font-style: italic;
}

.alpha p a:hover {
color: #ccc;
}

最佳答案

添加以下内容,它应该会按预期工作,基本上您需要以像素为单位的高度才能使动画继续工作,因此将其设置为自动会中断动画。在下面的代码中,我考虑了菜单中每个元素的高度 31px

.menu-item:hover ul {
height: 93px;

}

.menu-item:nth-child(1):hover ul {
height: 63px;

}

.menu-item:nth-child(2):hover ul {
height: 155px;

}

关于html - CSS 扩展导航问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28982801/

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