简体   繁体   English

仅当标题悬停在上方时,如何设置菜单才能滑出?

[英]How can I set up my menu to slide out, only when the header is hovered on?

How can I set up my menu to slide out, only when the header is hovered on? 仅当标题悬停在上方时,如何设置菜单才能滑出? I'm looking to set it up to function exactly like this: http://adirondack-demo.squarespace.com/ 我希望将其设置为完全像这样运行: http : //adirondack-demo.squarespace.com/

So on hover, it slides out, but doesn't push the content down. 因此,在悬停时,它会滑出,但不会压低内容。

Any ideas? 有任何想法吗? jQuery, or can this be done VIA CSS? jQuery,还是可以通过CSS完成?

Thought I'd add a javascript version as css animations can be tricky and are often not fully supported (though I'm not sure the other answer even uses animations and I can't seem to get it working). 以为我会添加一个JavaScript版本,因为CSS动画可能很棘手,而且通常不受完全支持(尽管我不确定其他答案甚至使用动画,而且我似乎也无法使其正常工作)。

Here is my: JsFiddle 这是我的: JsFiddle

bar is the top bar, baz is the page content and foo is the drop-down. bar是顶部栏, baz是页面内容, foo是下拉菜单。 On mouseover of bar , foo drops down without effecting the content, because it is positioned absolutely. bar鼠标悬停时, foo会下拉而不影响其内容,因为它的位置是绝对的。 The animation keeps it at the bottom of bar . 动画将其保留在bar的底部。 Feel free to play with it and ask questions. 随意使用它并提出问题。

One option: if the menu is a child element of the header. 一种选择:如果菜单是标题的子元素。 In that (markup) case you could set position: relative; 在这种情况下,您可以设置position: relative; to the header and position: absolute; 到标题和position: absolute; to the menu element to position the one below the other. 到菜单元素以将一个放置在另一个下方。 Use the CSS :hover pseudo class to make the menu visible. 使用CSS :hover伪类使菜单可见。

#header {
    position: relative;
}
#main-menu {
    position: absolute;
    top: 100%

    display: none;
}

#header:hover #main-menu,
#header #main-menu:hover {
    display: block;
}

If you want the menu to stay open, if the user crosses the border with his/her cursor, you may use an additional wrapper around the menu. 如果希望菜单保持打开状态,如果用户用光标越过边界,则可以在菜单周围使用其他包装纸。 That wrapper would become the target of the display settings. 该包装器将成为display设置的目标。 You could then assign that transparent wrapper a padding of your choice. 然后,您可以为该透明包装分配一个您选择的填充。 The menu stays visible as long as the cursor is within the padding of the wrapper element. 只要光标在包装器元素的填充内,菜单就保持可见。

#main-menu-wrapper {
    display: none;
    padding: 5em;
}

#header:hover #main-menu-wrapper {
#header #main-menu-wrapper:hover {
    display: block;
}

暂无
暂无

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

相关问题 仅用JS悬停时,如何在网站上显示元素? - How can I show a element on my site when hovered with only JS? 当我通过将滑出菜单位置设置为固定的浏览器运行网站时,没有滚动条出现 - No Scroll bar appears when I run my site through a browser with my slide out menu position set to fixed 当我快速移动菜单栏上的鼠标指针时,它会上下波动 - When i quickly move my mouse pointer on menu bar slide down and slide up, it is fluctuating 从左侧滑出时,如何在我的幻灯片菜单中添加“慢效果”? - How to add “slow effect” to my slide menu when slide out from left? 当我将光标移到侧边栏时,子菜单如何从侧边栏向下滑动 - how can the sub-menu slide down from the sidebar when i just take my cursor to it 使用 javascript 时,如何只让我的 header 菜单在屏幕尺寸大于 700 像素时缩小? - How can I only let my header menu shrink when the screen size is larger than 700px by using javascript? 当菜单没有悬停在反应时,我如何关闭菜单 - How can i make a menu close when it's not being hovered over on react 我不知道为什么菜单中的JQuery UI幻灯片缺少几个像素 - I can't figure out why my JQuery UI slide in menu is missing a few pixels 如何使标题在向下滚动时消失/消失并在向上滚动时重新出现? - How can I make my header fade out/disappear on scroll down and reappear on scroll up? 悬停时如何向网页上的单词添加弹出(工具提示)定义? - How can I add pop-up (tooltip) definitions to words on a webpage when hovered?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM