CSS显示属性上的过渡

不打扰是莪最后的温柔 提交于 2020-07-27 02:52:50

问题:

I'm currently designing a CSS 'mega dropdown' menu - basically a regular CSS-only dropdown menu, but one that contains different types of content. 我目前正在设计CSS“巨型下拉菜单”-基本上是一个常规的仅CSS下拉菜单,但其中包含不同类型的内容。

At the moment, it appears that CSS 3 transitions don't apply to the 'display' property , ie, you can't do any sort of transition from display: none to display: block (or any combination). 目前, 似乎CSS 3过渡不适用于'display'属性 ,即,您不能执行从display: nonedisplay: block (或任何组合)的任何过渡。

Is there a way for the second-tier menu from the above example to 'fade in' when someone hovers over one of the top level menu items? 当有人将鼠标悬停在顶层菜单项之一上时,是否可以通过上述示例使第二层菜单“淡入”?

I'm aware that you can use transitions on the visibility: property, but I can't think of a way to use that effectively. 我知道您可以在visibility:属性上使用过渡,但是我想不出一种有效使用它的方法。

I've also tried using height, but that just failed miserably. 我也尝试过使用高度,但是那不幸地失败了。

I'm also aware that it's trivial to achieve this using JavaScript, but I wanted to challenge myself to use just CSS, and I think I'm coming up a little short. 我还知道使用JavaScript实现此功能很简单,但是我想挑战一下自己仅使用CSS,而且我想说的还有点不足。


解决方案:

参考一: https://stackoom.com/question/DydV/CSS显示属性上的过渡
参考二: https://oldbug.net/q/DydV/Transitions-on-the-CSS-display-property
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!