下拉菜单CSS3的位置 [英] Drop down menu CSS3 position
问题描述
如果将鼠标悬停在User
菜单上,则菜单会显示在左侧=0.但是,它应该恰好显示在User
按钮"下方.我该怎么做? (仅CSS3)
If you hover over the User
menu, then the menu shows up at left = 0. But, it should show up exactly under the User
'button'. How can I accomplish this? (only CSS3)
推荐答案
将此规则添加到CSS:
Add this rule to your CSS:
.menu > li {
position: relative;
}
说明::如果在元素上指定position: absolute
,则top
和left
将相对于具有除static
以外的任何position
的第一个父元素.如果找不到类似的元素,则它将相对于页面(如您的情况).指定position: relative
是最简单的解决方案,因为该元素不会从文档流中删除.
Explanation: if you specify position: absolute
on an element, top
and left
will be relative to the first parent element that has any position
other than static
. If no element like that is found, it will be relative to the page (like in your case). Specifying position: relative
is the easiest solution because the element won't be taken out of the document flow.
这篇关于下拉菜单CSS3的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!