简体   繁体   English

如何使溢流y独立于溢流x运行

[英]How to make overflow-y operate independently of overflow-x

I'm working on some CSS for a navigation bar, and I need to use a max-height and overflow-y: scroll for the dropdown in order to make sure it will fit on the page. 我正在为导航栏使用一些CSS,并且需要使用max-heightoverflow-y: scroll下拉菜单以确保其适合页面。 However, whenever I set the overflow-y property to scroll, it seems to automatically enforce that overflow-x must also be set to scroll , and as a result, submenus become hidden. 但是,每当我将overflow-y属性设置为scroll时,似乎就会自动强制将overflow-x也必须设置为scroll ,结果,子菜单将被隐藏。

See the jsfiddle below for a working example 有关工作示例,请参见下面的jsfiddle

https://jsfiddle.net/5eyveyfz/ https://jsfiddle.net/5eyveyfz/

EDIT: I should clarify the use of my fiddle. 编辑:我应该澄清我的小提琴的用法。 The issue arises when you hover over the menu item titled "SubMenu 1" which shows the submenu in question. 当您将鼠标悬停在标题为“ SubMenu 1”的菜单项上时,就会出现此问题,该菜单项显示了该子菜单。 The expected behavior is that this submenu is visible without a scrollbar, but instead its behaving as though overflow-x was set to scroll 预期的行为是该子菜单在没有滚动条的情况下可见,但是其行为似乎是将overflow-x设置为scroll

While it is not doing this in your fiddle - is it possible the data you are populating in your actual build is forcing the table to overflow its width? 尽管您的摆弄没有这样做-您是否可能在实际构建中填充的数据迫使表溢出其宽度?

If so, change the container to overflow-x:hidden; 如果是这样,请将容器更改为overflow-x:hidden;。 in order to prevent the horizontal scroll bar. 为了防止水平滚动条。

Changing these values will show the dropdown directly below the submenu heading: 更改这些值将在子菜单标题的正下方显示下拉列表:

#menu > ul { 
 overflow-y:scroll;
 overflow-x:hidden;
 max-height:300px;
}

.submenu {
 position:relative;
 display: none;
 left:0; 
 top:0;
}

If you want to keep the left position you will need to make the container wider or change it to display:inline-block; 如果要保持在左侧位置,则需要使容器变宽或将其更改为display:inline-block;。 without a width set for it to adjust to the size of the content. 没有设置宽度以适应内容的大小。

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

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