当父菜单溢出时,下拉菜单会被切断

发布于 2025-01-11 14:13:08 字数 1131 浏览 2 评论 0原文

我创建了一个下拉菜单,我使用了我的真实项目源代码,这样就不会造成混淆:-

.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;,但没有任何效果,如何在溢出上方显示下拉菜单?

完整代码:- https://jsfiddle.net/ur5sL4qv/

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

还给你自由 2025-01-18 14:13:08

如果您使用 prime ng 或 bootstrap,它允许将下拉列表附加到主体或更高级别的容器以避免剪切。
您可以使用 [appendTo]="'body'" 来避免此问题

<p-dropdown class="w-full" formControlName="RequiredLOA" [options]="requires" 
   [appendTo]="'body'" optionLabel="name" optionValue="value" 
   optionDisabled="inactive">
</p-dropdown>

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

<p-dropdown class="w-full" formControlName="RequiredLOA" [options]="requires" 
   [appendTo]="'body'" optionLabel="name" optionValue="value" 
   optionDisabled="inactive">
</p-dropdown>
醉态萌生 2025-01-18 14:13:08
  1. 它将通过将高度分配给 main-container

来解决。 main-container {overflow-x: auto; height: 100vh;}

  1. 在 div.btn-dropdown-options 中使用相对位置而不是绝对位置

div.btn-dropdown-options {position:relative;}

  1. it will be resolved by assigning height to main-container

.main-container {overflow-x: auto; height: 100vh;}

or

  1. Use position relative instead of absolute in div.btn-dropdown-options

div.btn-dropdown-options {position: relative;}

呆° 2025-01-18 14:13:08

不确定我完全理解这个问题(我建议使用背景颜色来表示不需要的内容)。但是从 .main-container 中删除 overflow-x 并将 position:absolute 添加到下拉选项可以解决您的问题吗?

.btn-dropdown .btn-dropdown-options {
    position: absolute;
    right: 0;
}

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 adding position: absolute to dropdown options fixes your issue?

.btn-dropdown .btn-dropdown-options {
    position: absolute;
    right: 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文