Force Bootstrap dropdown menu to always display at the bottom and allow it go offscreen

前端 未结 3 668
谎友^
谎友^ 2021-02-07 02:38

When there is no room at the bottom of the viewport to fit dropdown menu, it is displayed at the top of its dropdown button. Is it possible alter this behavior and make dropdown

3条回答
  •  死守一世寂寞
    2021-02-07 03:02

    I wanted to tackle this problem with CSS alone.

    Bootstrap's dropdown's uses Popper.js for the positioning of the dropdown menu. This makes the task challenging since Popper.js seems to check and evaluate the position of the dropdown when the window is scrolled so I needed to use an !important rule to override Popper.js.

    Here's the code I came up with, based on your example.

    .dropdown-menu{
        transform: translate3d(5px, 35px, 0px)!important;
    }
    

    Example codepen: https://codepen.io/Washable/pen/xPdqVp

    This will always force the dropdown to be below the button, even if the button is at the bottom of the screen.

提交回复
热议问题