overflow-y:当overflow-x:hidden存在时,可见不起作用

时间:2012-07-17 10:35:46

标签: html css css3

在Chrome或Firefox中无法正常运行。这有什么解决方法吗?

   <!DOCTYPE html>
   <html>
   <head></head>
   <body>
    <h3>overflow-y:visible</h3>

    with overflow-x:hidden
    <div style="overflow-x:hidden;overflow-y:visible;width:100px;height:100px;   position:relative;background:#666;">
        <div style="top:20px;left:20px;    width:420px;height:420px;position:absolute;background:#420;">
        </div>
    </div>

    without overflow-x:hidden
    <div style="overflow-y:visible;width:100px;height:100px;position:relative;background:#666;">
        <div style="top:20px;left:20px; width:420px;height:420px;position:absolute;background:#420;">
        </div>
    </div>

   </body>
   </html>

http://jsfiddle.net/sMNyK/

现实生活场景涉及绝对必须具有overflow-x:hidden的组件,但这将触发弹出菜单,这些菜单需要能够在y方向上脱离元素。我应该将这些菜单放在其父组件之外,还是有更好的解决方法?

2 个答案:

答案 0 :(得分:25)

这可能与此处讨论的问题有关:CSS overflow-x: visible; and overflow-y: hidden; causing scrollbar issue

简而言之,当visibleoverflow-x使用overflow-y而另一个使用visible以外的其他内容时,visible值会被解释为{ {1}}。

答案 1 :(得分:3)

我认为你可以通过额外的包裹div来获得你想要的东西,它可以隐藏但没有设置position: relativesee fiddle):

<div style="overflow-y:visible;width:100px;height:100px;position:relative;background:#666;">
    <div style="overflow-x:hidden">
    ooooooooooooooooooooooooooooooooooooooooooooooo  
        <div style="top:20px;left:20px; width:420px;height:420px;position:absolute;background:#420;">
        </div>
    </div>
</div>
相关问题