The solution...just removed the display properties.
解决方案…刚刚删除了显示属性。
nav.main ul ul {
position: absolute;
list-style: none;
opacity: 0;
visibility: hidden;
padding: 10px;
background-color: rgba(92, 91, 87, 0.9);
-webkit-transition: opacity 600ms, visibility 600ms;
transition: opacity 600ms, visibility 600ms;
}
nav.main ul li:hover ul {
visibility: visible;
opacity: 1;
}
#2
16
Generally when people are trying to animate display: none what they really want is:
一般来说,当人们试图进行展示时:他们真正想要的是:
Fade content in, and
褪色的内容
Have the item not take up space in the document when hidden
该项目是否在隐藏时没有占用文档中的空间
Most popular answers use visibility, which can only achieve the first goal, but luckily it's just as easy to achieve both by using position.
大多数常见的答案都使用可见性,这只能实现第一个目标,但幸运的是,使用位置同样容易实现这两个目标。
Since position: absolute removes the element from typing document flow spacing, you can toggle between position: absolute and position: static (global default), combined with opacity. See the below example.
You can do this with animation-keyframe rather than transition. Change your hover declaration and add the animation keyframe, you might also need to add browser prefixes for -moz- and -webkit-. See https://developer.mozilla.org/en/docs/Web/CSS/@keyframes for more detailed info.