gpt4 book ai didi

html - CSS 下拉菜单过渡

转载 作者:行者123 更新时间:2023-11-28 04:33:55 24 4
gpt4 key购买 nike

我正在尝试为我正在处理的菜单添加下拉过渡,但似乎我不知道我做错了什么。菜单本身立即出现,忽略过渡效果。

我用于过渡的 CSS 代码:

-webkit-transition: height 0.3s ease-in;
-moz-transition: height 0.3s ease-in;
-o-transition: height 0.3s ease-in;
-ms-transition: height 0.3s ease-in;
transition: height 0.3s ease-in;
opacity:0;

据我所知,我应该将它添加到 nav ul ul CSS block 中,并将 opacity:1 添加到 nav ul li:hover > ul 但它不起作用。

这是菜单的完整代码。

HTML

<nav>
<ul>
<li><a href="http://www.www.com/">Menu 1</a></li>
<li><a href="http://www.www.com/">Menu 2</a></li>
<li><a>Dropdown Here</a>
<ul>
<li><a href="http://www.www.com/">Dropdown1</a></li>
<li><a href="http://www.www.com/">Dropdown2</a></li>
<li><a href="http://www.www.com/">Dropdown3</a></li>
</ul>
</li>
<li><a href="http://www.www.com/">Menu 4</a></li>
<li><a href="http://www.www.com/">Menu 5</a></li>
</ul>
</nav>

以及我正在使用的 CSS

nav ul {
background: #efefef;
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 25px;
border-radius: 10px;
list-style: none;
position: relative;
display: inline-table;
float:right;
z-index:9999;

}

nav ul ul {
display: none;
-webkit-transition: height 0.3s ease-in;
-moz-transition: height 0.3s ease-in;
-o-transition: height 0.3s ease-in;
-ms-transition: height 0.3s ease-in;
transition: height 0.3s ease-in;
opacity:0;
}

nav ul li:hover > ul {
display: block;
opacity:1;
}

nav ul:after {
content: "";
clear: both;
display: block;
}

nav ul li {
float: left;
}

nav ul li:hover {
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}

nav ul li:hover a {
color: #fff;
}

nav ul li a {
display: block;
padding: 30px 20px;
color: #757575;
text-decoration: none;
}

nav ul ul {
background: #5f6975;
border-radius: 0px;
padding: 0;
position: absolute;
top: 100%;
}

nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}

nav ul ul li a {
padding: 15px 40px;
color: #fff;
}

nav ul ul li a:hover {
background: #4b545f;
}

nav ul ul ul {
position: absolute; left: 100%; top:0;
}

最佳答案

你的过渡没有触发,因为你的元素的 height:hover 期间没有改变,只有 display不透明度。要使您的元素淡入 - 您需要将过渡属性更改为 opacityall

如果你想要过渡高度 - 你需要将你的元素 height 设置为 0,然后在 :hover 上更改它。

请注意 - 高度转换仅适用于指定的 height 值,不适用于 height: auto; 之类的值。有一个解决方法,如下所示:

ul {
transition: all 0.5s;
max-height: 0;
}

ul:hover {
max-height: 200px; //or whatever could be your max-height value - don't overdo it, will be crappy transition.
}

关于html - CSS 下拉菜单过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24614200/

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