简体   繁体   English

如何最好地制作悬停导航栏?

[英]How to best make a hover navbar?

How to make a navigation bar like dabblet that drops down on hover? 如何制作像dabblet这样的导航栏,将其悬停下来?

http://sampsonblog.com/289/of-dice-dabblet-and-css http://sampsonblog.com/289/of-dice-dabblet-and-css

Notice how when you mouse over "All" it appears to drop down from the top of the page. 请注意,当您将鼠标悬停在“全部”上时,它似乎是从页面顶部下拉的。 I know it is possible by making two divs with css position absolute such that "all" and "content" are positioned approrpiately: 我知道可以通过将两个div的css位置设为绝对,从而使“所有”和“内容”正确定位来实现:

<div id="content">-All content that would come with the dropdown here/div>
<div id="all">All</div>

Then using jquery to attach hover events to animate "all" and use an animation to cause "all" and "content" css to dropdown (I have two update the position of two separate dom eleements). 然后使用jquery将悬停事件附加到“ all”动画上,并使用动画使“ all”和“ content” css下拉(我有两个更新了两个单独的dom元素的位置)。 Is there some better way to structure it in the dom and potentially use CSS3 only to accomplish this than described and/or a better way to structure the dom such that I dont have to update both the position of content and all? 是否有某种更好的方法来在dom中进行结构化,并且有可能仅使用CSS3来完成上述操作,和/或是否有一种更好的方法来构建dom以使我不必同时更新内容和所有内容的位置?

Id surely would not doing it with javascript or jQuery, because its all possible with CSS3 only id肯定不会使用javascript或jQuery,因为只有CSS3才有可能

here an example or check out the fiddle http://jsfiddle.net/mpaas/ : 这是一个例子或查看小提琴http://jsfiddle.net/mpaas/

#naviWrapper {
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;

    position:absolute;
    top:-200px;
    height:200px;
    left:0px;
    right:0px;
    background:#ccc;
}

#naviWrapper:hover {
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;

    top:0px;
}

#naviButton {
    position:absolute;
    bottom:-60px;
    left:50%;
    margin-left:-50px;
    width:100px;
    height:60px;
    background:#000;
    color:#fff;
    text-align:center;
}


<div id="naviWrapper">

    <div id="naviButton">Hover!</div>

</div>

This works, because the button element is a child of the wrapper, so on hovering the naviButton, it will call a hover on the wrapper element, which animates through the queries given in on the top of the css styles. 这是可行的,因为button元素是包装器的子级,因此,将鼠标悬停在naviButton上时,它将在包装器元素上调用悬停,这将通过css样式顶部给出的查询进行动画处理。

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

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