CSS 中的定位:如何使绝对定位的内容显示在其相对定位的父级之外?
我遇到了一个让我发疯的问题,而如果你曾经面对过这个问题,那么对你来说应该很容易。
我正在使用下拉菜单。主菜单 div 是相对定位的,以便它按照 html 编写的顺序出现。此菜单包含绝对定位的按钮,在类别点击时出现在上方。 菜单后面就是内容,位于另一个相对定位的 div 中。
问题在于子导航按钮被内容 div 隐藏了。它们不仅出现在内容 div 后面,而且因为位于菜单 div 之外而被隐藏。
我的页面如下所示:
标题(相对)
菜单 - 类别 v 类别 v 类别 v
内容(相对)
所有这些都有一个静态定位的包含父级布局外观。
注意:我当然可以通过将菜单包含在内容 div 中来使其工作。最大的挑战是我希望它位于内容 div 之外,以便菜单可以更大。
希望我已经说清楚了,提前感谢您的回复。 任何帮助将不胜感激。
问候, 杜克
--------------编辑 ----------------
哇。不敢相信这是如此容易。
问题来自于我自动编写的溢出:隐藏。删除它,菜单的内容像魔术一样从 div 中弹出:) 实际上这真的很合乎逻辑,我现在明白了它正在工作;)
感谢大家和 Henry 如此快速地解决了它。 干杯!
I'm encountering a problem that is driving me crazy, while it should appear very easy for you if you have ever been faced to it.
I'm using a drop down menu. The main menu div is relatively positioned so that it appears in the order the html is written. This menu contains absolute-positioned buttons appearing above on category clicks.
Just after the menu comes the content, in another relatively positioned div.
The problem is that the subnav buttons are hidden by the content div. They don't just appear behind it, it is hidden because getting outside of the menu div.
My page looks like this:
Header (relative)
Menu - Category v Category v Category v
Content (relative)
All of these have a containing parent statically-positioned for the layout appearence.
Note : I got it of course working by including the menu in the content div. The big challenge is that I want it outside of the content div so that the menu can be larger.
Hope I've made myself clear, thanks in advance for your replies.
Any help would be appreciated.
Greetings,
Duke
---------------EDIT ----------------
Wow. can't believe that was so easy.
The problem came from the overflow:hidden that I write quite automatically. Removing it, the content of the menu pops out of the div like magic :) Actually that's really logical, i get it now that it's working ;)
Thanks everyone and Henry for resolving it so fast.
Cheers !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看您的网站,您确实在菜单 @
global.css
第 225 行设置了overflow: hide;
。去掉这个,您的菜单应该会显示出来。
编辑
我想应该做一个简短的解释。
overflow:hidden;
设置基本上会截断任何溢出。也就是说,如果容器设置为overflow:hidden;,任何溢出的内容(在本例中是越界菜单)都会被剪掉。有关
overflow
的文档。Looking at your site, you do have
overflow: hidden;
set on the menu @global.css
line 225.Get rid of this, and your menu should show up.
EDIT
I guess a brief explanation is in order. The
overflow: hidden;
setting basically truncates any overflow. That is to say, if a container is set tooverflow: hidden;
, any overflowing content (in this case your out-of-bounds menu) is clipped.Documentation on
overflow
.如果您发布代码将会非常有帮助,但是您可以尝试以下操作:将
z-index:9999
添加到子菜单项并查看它是否有效。It would be really helpful if you posted the code, but you can try this: add
z-index:9999
to the submenu items and see if it works.