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

后端 未结 16 1807
孤城傲影
孤城傲影 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:50

    I had some kind of scroll problem with most of solutions in this and other questions I've seen on SO. What worked for me was making the dropdown position inherit:

    .dropdown {
      position: inherit;
    }
    

    And then set the dropdown-menu position using JavaScript:

    $(document).on("show.bs.dropdown", function () {
      var dropdownToggle = $(this).find(".dropdown-toggle");
      var dropdownMenu = $(this).find(".dropdown-menu");
      dropdownMenu.css({
        "top": (dropdownToggle.position().top + dropdownToggle.outerHeight()) + "px",
        "left": dropdownToggle.position().left + "px"
      });
    });
    

    Here is a working example: http://jsfiddle.net/ck66ee9q/

提交回复
热议问题