Bootstrap 3 modal fires and causes page to shift to the left momentarily / browser scroll bar problems

后端 未结 24 1414
遥遥无期
遥遥无期 2020-12-12 12:08

I am working on a site using Bootstrap 3.1.0.

You\'ll notice when the modal window opens, the browser scroll bar just disappears for a split second, then comes back.

相关标签:
24条回答
  • 2020-12-12 13:05

    Implemented this simple solution

    .modal-open {
    
      padding-right: 0 !important;
    
    }
    
    html {
    
      overflow-y: scroll !important;
    
    }
    
    0 讨论(0)
  • 2020-12-12 13:05

    For Bootstrap-4.3.x use the following css:

    .modal-open {
        padding-right: 0 !important;
    }
    
    /* if you have .navbar in your page then add padding-right for your .navbar (default is 16px) */
    .modal-open .navbar {
        padding-right: 16px !important;
    }
    

    That's it. Nothing else is needed like: JavaScript code to add some .class in your body and then adding CSS codes to style them.

    0 讨论(0)
  • 2020-12-12 13:06
    .modal {
        overflow-y: auto;
    }
    
    .modal-open {
        overflow: auto;
    }
    
    .modal-open[style] {
        padding-right: 0px !important;
    }
    

    Thanks to ben and cjd.

    The above code seems to work for me.

    0 讨论(0)
  • 2020-12-12 13:06

    If you have fixed navbar and dont want to scroll body to top when modal is opened use this style

    .modal-open {
        overflow: visible;
    }
    .modal-open, .modal-open .navbar-fixed-top, .modal-open .navbar-fixed-bottom {
        padding-right:0px!important;
    }
    
    0 讨论(0)
  • 2020-12-12 13:07

    The best solution for me was use this settings. It works for web and mobile

    .modal-open {
       overflow: hidden;
       position: absolute;
       width: 100%;
       height: 100%;
    }
    
    0 讨论(0)
  • 2020-12-12 13:08

    I fixed this issue by adding this code in my css file:

    body {
        padding-right: 0px !important;
    }
    
    0 讨论(0)
提交回复
热议问题