当父菜单溢出时,下拉菜单会被切断
我创建了一个下拉菜单,我使用了我的真实项目源代码,这样就不会造成混淆:-
.main-container {
overflow-x: auto;
}
div.btn-dropdown-options {
font-family: "Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 20px;
position: absolute;
z-index: 1000;
top: calc(100% + 8px);
left: 0;
min-width: 180px;
margin-top: 4px;
overflow: auto;
border: 1px solid rgba(0,0,0,0.05);
border-radius: 8px;
background: #fff;
visibility: hidden;
opacity: 0;
transition: opacity 2s, visibility 2s;
-webkit-box-shadow: 0px 1px 2px rgba(128,138,157,0.12),0px 8px 32px rgba(128,138,157,0.24);
box-shadow: 0px 1px 2px rgba(128,138,157,0.12),0px 8px 32px rgba(128,138,157,0.24);
}
我有一个下拉菜单 div.btn-dropdown-options 和一个父容器 主容器。当我单击切换按钮显示下拉菜单时,由于溢出属性,它被切断,我使用了position:absolute和z-index:1000;,但没有任何效果,如何在溢出上方显示下拉菜单?
I created a DropDown menu, I used my real project source code for it so that there should be no confusion:-
.main-container {
overflow-x: auto;
}
div.btn-dropdown-options {
font-family: "Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 20px;
position: absolute;
z-index: 1000;
top: calc(100% + 8px);
left: 0;
min-width: 180px;
margin-top: 4px;
overflow: auto;
border: 1px solid rgba(0,0,0,0.05);
border-radius: 8px;
background: #fff;
visibility: hidden;
opacity: 0;
transition: opacity 2s, visibility 2s;
-webkit-box-shadow: 0px 1px 2px rgba(128,138,157,0.12),0px 8px 32px rgba(128,138,157,0.24);
box-shadow: 0px 1px 2px rgba(128,138,157,0.12),0px 8px 32px rgba(128,138,157,0.24);
}
I have a dropdown menu div.btn-dropdown-options and a parent container main-container. When I click on the toggle button to show the dropdown it gets cut off due to overflow property, I have used position: absolute and z-index: 1000;, but nothing is working, how can I show the dropdown menu above the overflow?
full-code :- https://jsfiddle.net/ur5sL4qv/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 prime ng 或 bootstrap,它允许将下拉列表附加到主体或更高级别的容器以避免剪切。
您可以使用
[appendTo]="'body'"
来避免此问题If you are using prime ng or bootstrap, it allows dropdown to be append to the body or a higher level container to avoid clipping.
you can you use
[appendTo]="'body'"
to avoid this issue来解决。 main-container {overflow-x: auto; height: 100vh;}
或
div.btn-dropdown-options {position:relative;}
.main-container {overflow-x: auto; height: 100vh;}
or
div.btn-dropdown-options {position: relative;}
不确定我完全理解这个问题(我建议使用背景颜色来表示不需要的内容)。但是从 .main-container 中删除
overflow-x
并将position:absolute
添加到下拉选项可以解决您的问题吗?Not sure I fully understand the problem (I suggest using background colors for signaling what's undesireable). But does removing
overflow-x
from .main-container and addingposition: absolute
to dropdown options fixes your issue?