简体   繁体   English

转换延迟不适用于边框

[英]Transition delay doesn't work with border

 .hovereffect:hover > .hidden { opacity: 1; height: 1.5em; padding: 0.5em 1em 0.5em 2em; border: thin solid white; transition-delay: 0s; } .hovereffect .hidden { opacity: 0; clear: both; height: 0em; padding: 0em; border: none; transition-property: opacity height padding border; transition-duration: 400ms; transition-delay: 1s; } nav { float: right; width: 15em; margin: 0.1em 0em 0.1em 1em; font-variant: small-caps; } nav a { display: block; background-color: #FBF0D4; color: #725D29; border: thin solid white; padding: 0.5em 1em; text-decoration: underline; } nav a:hover, nav a:active { background-color: #725D29; color: #FBF0D4; } 
 <nav> <a href="/guitar">Menu 1</a> <div class="hovereffect"> <a href="/software">Menu 2</a> <a class="hidden" href="/software/practicaluml">Submenu 1</a> <a class="hidden" href="/software/trusting_trust">Submenu 2</a> </div> <a href="/sketches">Menu 3</a> <a href="/sketches">Menu 4</a> </nav> 

JSFiddle: http://jsfiddle.net/ke9cc0c7/ JSFiddle: http : //jsfiddle.net/ke9cc0c7/

I am trying to show a list of sub menus on :hover over a menu item, which is hidden otherwise. 我试图在:hover菜单项上显示子菜单列表,否则将其隐藏。 But the collapsing list was causing menu items to change position the moment user moved mouse away from the submenu, forcing an unsuspecting user to chase after a preferred link. 但是,折叠列表导致菜单项在用户将鼠标移离子菜单时改变位置,从而迫使毫无戒心的用户追随首选链接。 So I decided to add a transition-delay. 因此,我决定添加一个过渡延迟。 But for some reason it doesn't work on border! 但是由于某种原因,它在边界上不起作用! (See the JSFiddle link for demo.) The moment user moves mouse away from the submenu, border is reset to 0 without any delay. (有关演示,请参阅JSFiddle链接。)当用户将鼠标从子菜单上移开时,边框将立即重置为0。

Any particular mistake I am making? 我正在犯任何特别的错误? I am just a learner. 我只是一个学习者。

That is because the border-style property is not a transitionable property . 那是因为border-style属性不是可转换属性 When you transition from border:none to border: thin solid white , the border-style is also being changed along with the border-color and the border-width . 当您从border:none过渡到border:noneborder: thin solid white border-style也会随着border-colorborder-width The initial value of border-style is none . border-style初始值为none

Setting border: 0px solid white as the initial value would make it work properly because border-style remains the same even though border itself is removed because the width is 0px and would not produce any visual difference. border: 0px solid white设置为初始值将使其正常工作,因为即使因为宽度为0px而删除了边框本身, border-style仍保持不变,不会产生任何视觉差异。

 .hovereffect:hover > .hidden { opacity: 1; height: 1.5em; padding: 0.5em 1em 0.5em 2em; border: thin solid white; transition-delay: 0s; } .hovereffect .hidden { opacity: 0; clear: both; height: 0em; padding: 0em; border: 0px solid white; transition-property: opacity height padding border; transition-duration: 400ms; transition-delay: 1s; } nav { float: right; width: 15em; margin: 0.1em 0em 0.1em 1em; font-variant: small-caps; } nav a { display: block; background-color: #FBF0D4; color: #725D29; border: thin solid white; padding: 0.5em 1em; text-decoration: underline; } nav a:hover, nav a:active { background-color: #725D29; color: #FBF0D4; } 
 <nav> <a href="/guitar">Menu 1</a> <div class="hovereffect"> <a href="/software">Menu 2</a> <a class="hidden" href="/software/practicaluml">Submenu 1</a> <a class="hidden" href="/software/trusting_trust">Submenu 2</a> </div> <a href="/sketches">Menu 3</a> <a href="/sketches">Menu 4</a> </nav> 

You can find the full list of animatable/transitionable properties in the spec here . 您可以在此处规范中找到可动画/可转换属性的完整列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM