gpt4 book ai didi

Movement of div causing a glitch(Div的移动导致故障)

转载 作者:bug小助手 更新时间:2023-10-25 22:36:22 26 4
gpt4 key购买 nike



I have a submenu that becomes visible when hovered on a nav element.When the element is no longer hovered on, the submenu is goes invisible and moves up. I have attached part of my code below.The problem I am facing is,since the submenu is right below the nav element, the upward movement is making the submenu active during the transition and thereby causing it to glitch. How do I fix this

我有一个子菜单,当悬停在导航元素上时,它会变为可见。当该元素不再悬停时,子菜单将变为不可见并向上移动。我已经在下面附上了我的部分代码。我面临的问题是,由于子菜单就在导航元素的正下方,向上移动会在转换期间使子菜单处于活动状态,从而导致它出现故障。我怎么解决这个问题呢?




#sub-menu {
position: absolute;
background-color: red;
visibility: hidden;
width: 13.2rem;
right: 54%;
top: 3.9%;
height: 330%;
line-height: 30px;
border-radius: 5px;
z-index: 600;
opacity: 0;
transition: 0.1s ease;
}

#nav>li:hover #sub-menu {
visibility: visible;
top: 7.9%;
opacity: 1;
}

<div>
<nav>
<ul id="nav">
<li>
<a>Test1</a>
<ul id="sub-menu">
<li><a href="">Test2</a></li>
</ul>
</li>
</ul>
</nav>
</div>




更多回答

You could add #nav>li { position:relative; } to prevent the sub-menu from overlapping. Or use #sub-menu { pointer-events: none } to prevent the mouse from interacting with the sub-menu. Or transition the min-height value rather than the top value. #sub-menu { transition: 0.1s ease; } targets all css-rules for a given selector and can be made more specific by targetting individual rules: transition: min-height 2s. What animation/effect are you aiming to produce?

您可以添加#NAV>li{POSITION:Relative;}以防止子菜单重叠。或者使用#子菜单{POINTER-EVENTS:NONE}阻止鼠标与子菜单交互。或者转换最小高度值而不是顶值。#子菜单{TRANSION:0.1S EASE;}针对给定选择器的所有css规则,并可以通过针对单独的规则:TRANSION:MIN-HEIGH 2S来使其更加具体。你的目标是制作什么动画/效果?

hey, I already have nav position as a relative. I can't use pointer-events as none because I need to interact with the submenu. The animation I'm trying to achieve is submenu dropping down

嘿,我已经有一个亲戚的导航位置了。我不能使用指针事件作为无,因为我需要与子菜单交互。我想要实现的动画是下拉子菜单

优秀答案推荐
更多回答

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