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

后端 未结 16 1753
孤城傲影
孤城傲影 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 19:05

    jesus christ people yall take something so simple and make it complicated. Change the dropdown position to position:static; and BLAMMMMMMM! Problem fixed. I think I saw someone else mention this but then they were drowned out by overly bloated and hackish fixes :(

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

    I faced the same issue, with needing to have overflow:hidden set, but yet have the drop-down not be clipped.

    However my situation involved the Bootstrap Carousel, so I decided a valid solution would make the overflow visible only when the dropdown is opened, and when it closes, the overflow can return to hidden. This solution might work for others, so I'm sharing it.

    $('.dropdown-toggle').click(function() {
      var $container = $(this).parent('.carousel-inner');
      $container.css('overflow','visible');
      $(document).one('click', function() {
          $container.css('overflow','');
      });        
    });
    

    Note, this doesn't check for Esc key being used to close the dropdown, but in my case this wasn't an issue. My own version uses a class to apply the style which some devs might prefer instead of modifying inline CSS.

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

    You can also try this one by replacing yourDivId by the id of your div.

    $('.dropdown').on('show.bs.dropdown', function() {
        $('#yourDivId').css('overflow-x', 'visible');
    });
    
    $('.dropdown').on('hidden.bs.dropdown', function() {
        $('#yourDivId').css('overflow-x', 'hidden');
    });
    
    0 讨论(0)
  • 2020-12-02 19:07

    I was facing the same issue and after searching for hours.. I created a event handler to catch the dropdown-toggle and get the positions and attach it dynamically. so that it doesnt get cut off.

    Here is the simple code I used. Try it out if this helps.

    $('.dropdown-toggle').click(function (){
         dropDownFixPosition($('button'),$('.dropdown-menu'));
     });
     function dropDownFixPosition(button,dropdown){
        var dropDownTop = button.offset().top + button.outerHeight();
        dropdown.css('top', dropDownTop + "px");
        dropdown.css('left', button.offset().left + "px");
      }
    
    0 讨论(0)
提交回复
热议问题