【问题标题】:Handle twitter bootstrap dropdown clipped issue having overflow auto on container处理容器上自动溢出的 twitter bootstrap 下拉剪辑问题
【发布时间】:2023-04-04 04:10:01
【问题描述】:

Bootstrap 下拉菜单被截断,我查看了以下问题中提到的所有选项,但没有奏效。

Bootstrap drop down cutting off

Twitter Bootstrap Button dropdown z-index layering issue

z-index issue with twitter bootstrap dropdown menu

要求

  • 我想在主 div 中滚动
  • 我希望引导下拉菜单不会被剪裁
  • 不应更改 div 和下拉菜单的高度宽度

Plunker: http://plnkr.co/edit/HOKKYJ?p=preview

<!DOCTYPE html>
<html>

  <head>
    <title>Clipping problem</title>
        <link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" />
        <link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
        <script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
        <script data-require="bootstrap@*" data-semver="3.3.5" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
     <script>
            angular.module("myApp", []).controller("MainCtrl", function($scope) {
            });
        </script>
  </head>

 <body style="height:100%;" ng-app="myApp">
        <div style="background: indianred; position: relative; left:40%; height: 200px; width: 250px; overflow-y: auto;">
                <div ng-repeat="num in [1,2,3,4,5]">
                    <div style="background: bisque; margin:5px; height: 50px;">
                        <div style="position: relative; float: right">
                            <button class="dropdown-toggle" data-toggle="dropdown">Click me Brother...!!</button>
                            <div class="dropdown-menu">
                                <div style="text-wrap: none; white-space: nowrap;">I am a text......................................!!</div>
                                <div style="text-wrap: none;white-space: nowrap;">I am a also text.................................!!</div>
                                <div style="text-wrap: none;white-space: nowrap;">Another text........................................................................................!!</div>
                                <div style="text-wrap: none;white-space: nowrap;">One more text.............................!!</div>
                                <div style="text-wrap: none;white-space: nowrap;">Aha one more text...........................................................................!!</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
    </body>

</html>

有问题:

我想要什么:

提前致谢

【问题讨论】:

  • 在您的 Plunkr 中,您能否将其重构为使用样式表而不是内联样式?这样调试会更容易。
  • @Trans 你需要看整个句子。?因为如果需要,那么如何管理因为你不想打断句子,你也不想在 x 方向上进行溢出滚动
  • @Trans 那么您的预期结果是什么。?你能解释更多吗?
  • 主 div 下拉菜单的溢出属性应该是完整的。不应剪切该下拉内容(无论如何),在问题中添加两个屏幕截图以满足要求
  • 谁能回答我的问题?

标签: jquery css twitter-bootstrap


【解决方案1】:

问题

我使用 Bootstrap 3 并且在使用自动溢出的 div 容器时遇到了同样的问题。它包含一个必须从容器中弹出的下拉菜单。

解决方案

解决方法是将 position:fixed 设置为下拉菜单,然后在单击时使用 jQuery 计算坐标。坐标是使用 offset() 计算的,因此它相对于文档窗口而不是元素父级。

此解决方案可能也适用于溢出:隐藏容器。

CSS

.somecontainer .dropdown-menu {
    position:fixed;
}

jQuery

$(".somecontainer .dropdown").on('click', function() {
    $(this).find('.dropdown-menu').css('top',$(this).offset().top);
    $(this).find('.dropdown-menu').css('left',$(this).offset().left);
});

可选地添加这个来隐藏窗口调整大小的下拉菜单:

$( window ).resize(function() {         
    $('.somecontainer .dropdown-menu').parent().removeClass('open');
}); 

【讨论】:

  • 我可以确认这适用于溢出:隐藏容器。事实上,这是唯一对我有用的解决方案
【解决方案2】:

其实这与下拉无关。 CSS 逻辑 - 绝对元素不能在 div(overflow:auto) 内以固定高度进行裁剪。

解决方案会有点混乱,但您需要将下拉 div 附加到滚动容器之外,并将其与触发链接对齐。

【讨论】:

  • 同意,现在的问题是如何做到这一点?
【解决方案3】:

您好,很高兴给出这个答案,因为我试图为此付出努力

bdw 我同意 Chetan 的观点,即您需要将下拉 div 从主 div 中制作出来

虽然我对角度不太了解,所以我不能说你的限制是什么

虽然我设法以我的方式工作

 <body style="height:100%;" ng-app="myApp">
        <div class="main-div">
                <div ng-repeat="num in [1,2,3,4,5]">
                    <div class="repeated-div">
                        <div class="grouped-dd">
                            <button class="dropdown-toggle" data-toggle="dropdown">Click me Brother...!!</button>
                            <div class="dropdown-menu temp">
                                <div class='no-wrap-text-div' title="I am a text......................................!!">I am a text......................................!!</div>
                                <div class='no-wrap-text-div' title="I am a also text.................................!!" >I am a also text.................................!!</div>
                                <div class='no-wrap-text-div' title="Another text........................................................................................!!">Another text........................................................................................!!</div>
                                <div class='no-wrap-text-div' title="One more text.............................!!">One more text.............................!!</div>
                                <div class='no-wrap-text-div' title="Aha one more text...........................................................................!!">Aha one more text...........................................................................!!</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
    </body>

CSS

 .temp {
            max-width: 43px;
            min-width: 142px;
            text-overflow: ellipsis;
            overflow: hidden;
        }
        .no-wrap-text-div{
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            max-width: 160px;
        }

my tried Demo

请注意:虽然有一点是您需要给出所有 div 的标题 如果您将包含在动态环境中,那么动态。

还有一件事我覆盖了引导程序的最小宽度 dropmenu 的宽度为 160 px 到 142 px,根据 我的建议也是

【讨论】:

  • @Trans 请检查答案
  • @Trans 那么你需要什么?或预期的结果。>?
  • 我加了截图哥们...!!
猜你喜欢
  • 2017-06-28
  • 2014-12-29
  • 2012-06-13
  • 1970-01-01
  • 2022-09-29
  • 2013-04-27
  • 2012-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多