作者:七里汀 | 来源:互联网 | 2023-05-18 23:12
IvegotawebsiteImbuildingforpersonaluse.Thiswebsitehasadropdownmenuthatisanimated
I've got a website I'm building for personal use. This website has a dropdown menu that is animated by CSS3 animations. I quite enjoyed the look and feel of the result, until I realize that the List Items inside the Unordered List weren't visible/invisible relative to the dropdown's height. The information I seek is a method of resolving this. It's very annoying, especially given the time I've invested into something that seems so simple...
我有一个个人网站。这个网站有一个下拉菜单是由CSS3动画。我很喜欢结果的外观和感觉,直到我意识到无序列表中的列表项相对于下拉列表的高度是不可见/不可见的。我寻找的信息是解决这个问题的一种方法。这很让人讨厌,尤其是考虑到我花时间去做一些看起来很简单的事情……
Pertinent HTML:
相关的HTML:
Pertinent CSS:
相关的CSS:
@keyframes dropdown {
from { height: 0px; }
to { height: 77px; }
} @-webkit-keyframes dropdown {
from { height: 0px; }
to { height: 77px; }
}
.dMaster {
margin: 0;
padding: 0;
text-align: center;
} .dChild {
margin: 0;
padding: 0;
height: 19px;
width: 60px;
float: left;
list-style: none;
} .dChild:hover {
color: #000;
background: #C60;
border: 1px solid #FFF;
border-top: none;
text-shadow: 1px 1px 5px #FFF;
} .dMaster2 {
padding: 0;
position: absolute;
min-width: 60px;
text-align: center;
background: #C60;
border: 1px solid #FFF;
margin: -2px 0 0 -1px;
visibility: hidden;
} .dChild2 {
opacity: 0.5;
padding: 2px 5px;
list-style: none;
-webkit-transition: opacity 0.4s;
-moz-transition: opacity 0.4s;
-o-transition: opacity 0.4s;
} .dChild2:hover {
opacity: 1.0;
} ul li:hover ul {
color: #FFF;
visibility: visible;
animation: dropdown 0.2s ease-out;
-webkit-animation: dropdown 0.2s ease-out;
}
I've tried for an hour or two with many different techniques without avail. If needed, there's a JSFiddle here. Any help is greatly appareciated!
我试了一两个小时,用了很多不同的技术,但都没有效果。如果需要,这里有一个JSFiddle。任何帮助都是显而易见的!
Side note: The dropdown menu is on the About. It may not be apparent at first, but the List Items are quite visible when the UL is extending downward.
侧边注:下拉菜单在左右。一开始可能不是很明显,但是当UL向下扩展时,列表项是很明显的。
2 个解决方案
2
May that be what you're looking for ?
这就是你想要的吗?
Basically it uses a different transition-delay
for each line.
基本上,它对每一行使用不同的传递延迟。
I put an effort to make everything clearer on this fiddle when I didn't in the last one. You should really check the second for a good point of vue.
我努力让一切变得更清楚,当我没有在最后一个。你真的应该检查第二个关于vue的问题。
The goal is to achieve to display them one at a time. Two solutions for that :
目标是实现一次显示一个。有两种解决方法:
- An unique id per line
- 每行唯一的id
- Use the nth-child to get each-line.
- 使用n -child来获取每条线。
Let's say we have 3 items to display in 3s. Here is our time line :
假设我们有3个项目在3s中显示。这是我们的时间线:
t Action
_____________
0 | The rectangle begins to display.
|
1 | Rectangle at 1/3 of its height. We display our item n° 1.
|
2 | Rectangle at 2/3 of its height. We display our item n° 2.
|
3 | Rectangle at 3/3 of its height. We display our item n° 3.
v
Let's revue the code :
让我们来看看这个代码:
HTML
HTML
Hover me
Our goal is simple :
我们的目标很简单:
We want that if we drag the mouse over the
tag, it displays progressively the
and the different
elements. Moreover, we want that it stays if the mouse is over the menu, but vanishes instantly if the mouse goes out of the
or
.
我们希望,如果我们将鼠标拖过标签,它会逐步显示
和不同的
- 元素。此外,如果鼠标在菜单上,我们希望它保持不变,但如果鼠标离开或
- 元素。此外,如果鼠标在菜单上,我们希望它保持不变,但如果鼠标离开或,则立即消失。
CSS
CSS
Basics
基础知识
ul { /* Hidden and width no height */
visibility: hidden;
background-color: white;
height: 0px;
border: 1px solid black;
}
a:hover ~ ul { /* When the mouse goes over the it becomes visible and begins the transition */
visibility: visible;
background-color: orange;
height: 60px;
transition: height 3s;
}
Now we get to the "tricky part" :
现在我们来谈谈“棘手的部分”:
a:hover ~ ul li { /* Default behaviour for appearing */
opacity: 1;
transition: opacity 0.2s;
}
/* And now for each child, its custom delay :*/
a:hover ~ ul li:nth-child(1) {
transition-delay: 1s;
}
a:hover ~ ul li:nth-child(2) {
transition-delay: 2s;
}
a:hover ~ ul li:nth-child(3) {
transition-delay: 3s;
}
And TADAAAAM ! Easy peasy !
和TADAAAAM !容易peasy !
In the other side, to avoid them to disappear progressively:
另一方面,避免它们逐渐消失:
/* To make the depop instantly */
a ~ ul li {
opacity: 0;
transition-delay: 0s;
}
a ~ ul li:nth-child(1) {
transition-delay: 0s;
}
a ~ ul li:nth-child(2) {
transition-delay: 0s;
}
a ~ ul li:nth-child(3) {
transition-delay: 0s;
}
And here you go. Of course, it's not very dynamic, and if you need to do this for each child, it will soon be boring. But you can use scripts to generate that code. :)
这里你去。当然,它不是动态的,如果你需要为每个孩子做这个,很快就会很无聊。但是您可以使用脚本来生成代码。:)
Hope it helped.
希望它帮助。