gpt4 book ai didi

html - 悬停时的CSS3下拉菜单

转载 作者:太空宇宙 更新时间:2023-11-03 23:27:57 28 4
gpt4 key购买 nike

我想构建一个纯 CSS 的菜单。没有 jQuery。

我已经走到这一步了,但无法让菜单从顶部滑入。这是一个 fiddle (奇怪的是,它看起来不像我的菜单......但是所有的样式都在那里)

一些代码:HTML:

<div class="menu">
<ul>
<li class="blue"> <a style="text-decoration: none" href="/who-we-are">Who We Are</a>

</li>
<li class="red"> <a style="text-decoration: none" href="/services">Services</a>

<ul>
<li> <a href="/post1" rel="bookmark" title="Permanent Link to Post 1">Post 1</a>

</li>
<li> <a href="/post2" rel="bookmark" title="Permanent Link to Post 2">Post 2</a>

</li>
<li> <a href="/post3" rel="bookmark" title="Permanent Link to Post 3">Post 3</a>

</li>
</ul>
</li>
<li class="orange"><a style="text-decoration: none" href="/packages">Packages</a>

<ul>
<li> <a href="/post1" rel="bookmark" title="Permanent Link to Post 1">Post 1</a>

</li>
<li> <a href="/post2" rel="bookmark" title="Permanent Link to Post 2">Post 2</a>

</li>
<li> <a href="/post3" rel="bookmark" title="Permanent Link to Post 3">Post 3</a>

</li>
</ul>
</li>
<li class="green"><a style="text-decoration: none" href="/contact-us">Contact</a>

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

还有我的 CSS:

.menu {
float: left;
margin-top: 0px;
}
.blue, div.item.blue div {
color: #009dc4;
}
.red, div.item.red div {
color: #fe4f00;
}
.orange, div.item.orange div {
color: #ff5958;
}
.green, div.item.green div {
color: #50c402;
}
.menu ul li a {
display: block;
height: 45px;
padding-top: 18px;
}
.menu ul li a:visited {
color: inherit;
}
.menu ul {
list-style: none;
margin: 0;
}
.menu ul li {
display: inline-block;
position: relative;
cursor: pointer;
width: 145px;
font-family: Georgia;
height: 45px;
font-size: 20px;
line-height: 22px;
font-weight: bold;
padding-left: 5px;
margin-top: 0px;
margin-right: 46px;
border-bottom: 5px solid;
z-index: 5000;
}
.menu ul li:hover {
color: #ffffff !important;
}
.menu ul li.blue:hover {
background-color: #009dc4;
border-bottom: 5px solid #009dc4;
}
.menu ul li.red:hover {
background-color: #fe4f00;
border-bottom: 5px solid #fe4f00;
}
.menu ul li.orange:hover {
background-color: #ff5958;
border-bottom: 5px solid #ff5958;
}
.menu ul li.green:hover {
background-color: #50c402;
border-bottom: 5px solid #50c402;
}
.menu ul li ul {
display: none;
opacity: 0;
visibility: hidden;
position: absolute;
top: 45px;
}
.menu ul li ul li {
display: block;
font-size: 12px;
border-bottom: none;
width: 145px;
color: #ffffff;
padding-left: 0px;
height: 34px;
line-height: normal;
position: relative;
left: -5px;
}
.menu ul li ul li a {
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
height: auto;
padding: 10px 5px;
font-size: 12px;
background-color: #4fc7c1;
-webkit-transition: all 0.1s;
-moz-transition: all 0.1s;
-ms-transition: all 0.1s;
-o-transition: all 0.1s;
transition: all 0.1s;
}
.menu ul li ul li a:hover {
background: #a3edf5;
}
.menu ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
.menu > ul > li:last-of-type {
margin-right: 0px;
}

如果有人可以帮助让幻灯片正常工作,我将不胜感激。

最佳答案

不幸的是,没有办法制作动画 height:0height:auto使用 CSS(从 CSS3 开始)。但是有一个解决方法使用 max-height记录在这里:http://css3.bradshawenterprises.com/animating_height/

根据该逻辑,我从您的 JS fiddle 创建了一个简单的示例。它所做的只是设置 css 样式 max-height:0在下拉菜单上 <ul>元素,max-height 的一些转换css 属性,然后是一个大 max-height悬停在菜单上的值。

不幸的是 max-height必须是硬编码的(不能是自动的)所以我们在这里受到限制;但如果您确信您的菜单永远不会超过 500 像素,那么您只需输入 500 像素即可。

这是 fiddle : http://jsfiddle.net/6ame5wcu/4/

关于html - 悬停时的CSS3下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26210517/

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