Bootstrap dropdown clipped by overflow:hidden container, how to change the container?

后端 未结 16 1752
孤城傲影
孤城傲影 2020-12-02 18:07

Using bootstrap, I have a dropdown menu(s) inside a div with overflow:hidden, which is needed to be like this. This caused the dro

相关标签:
16条回答
  • 2020-12-02 18:54

    Change the div property to overflow:visible;, or Set Position:absolute; on .dropdown class like

    .bs-example .dropdown{position:absolute;}
    

    See the Working Code: http://jsfiddle.net/guruWork/3x1f8ng5/

    0 讨论(0)
  • 2020-12-02 18:54

    I ended up using tippy.js insead of bootstrap dropdown, which solved this overflow:hidden parent problem, since dropdown can be located in body tag.

    0 讨论(0)
  • 2020-12-02 18:55

    Ng Bootstrap >= 4.1.0 (Angular powered Bootstrap) solution:

    For anyone struggling with the same issue, but using ng-bootstrap, here's a solution for you - use container="body" option in your ngbDropdown:

    <div ngbDropdown container="body">
        <!-- Dropdown menu goes here -->
    </div>
    
    0 讨论(0)
  • 2020-12-02 19:00

    All the answers mentioned here didn't work for me, so I found another workaround:

    $('.dropdown').on('shown.bs.dropdown', function () {
        const dropdown = $(this);
        setTimeout(function () {
            dropdown.find('.dropdown-menu').css({'top': dropdown.offset().top - $(window).scrollTop(), 'left': dropdown.offset().left - $(window).scrollLeft(), 'position': 'fixed'});
        }, 1);
    });
    

    The timeout is necessary as the event handler is fired before bootstraps sets the CSS of the dropdown therefore overwriting it

    0 讨论(0)
  • 2020-12-02 19:02

    Changing the container is possible using jQuery e.g. $(".dropdown").insertAfter(".bs-example");

    See this code for example: https://jsfiddle.net/SolveItSimply/pwmyvsw6/

    I don't recommend this though, as you will lose any of the usefulness of Bootstrap positioning and keeping the drop-down elements in order will be messy.

    Instead, you could use overflow:visible along with the 'hidden' class to your advantage, hiding any element that overflows with JavaScript. Here's an example: http://jsfiddle.net/SolveItSimply/z14c210x/

    You will need to check the contained elements when the div is first visible and whenever the height of the container changes, which I've tried to demonstrate in my example.

    0 讨论(0)
  • 2020-12-02 19:03

    I had a div element with a Bootstrap panel class containing DevExpress ComboBoxes contained in div elements with Bootstrap col-lg classes.

    I had a problem of the panel background color or border color bleeding to the div above. To resolve that I added overflow:hidden; to the panel but that caused the ComboBox's dropdown to be cut off. I added style="position: inherit" to those div elements within the panel containing the ComboBoxes and that solved the problem.

    <div class="col-sm-12" style="position: inherit">
    <div class="col-sm-4" style="position: inherit">
     <dx:aspxComboBox></dx:aspxComboBox>
    </div>
    </div>
    

    This solution I found here.

    0 讨论(0)
提交回复
热议问题