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.
I had this problem with Bootstrap 4. I have html { overflow-y: scroll; }
and I think it is a problem but after add .modal-open[style] { padding-right: 0px !important; }
to my local css file, everything work perfect!
.modal-open[style] {
padding-right: 0px !important;
}
html, body{
padding-right: 0px !important;
position: relative!important;
}
try this code really it's working
My Jquery solution:
var nb = $('nav.navbar-fixed-top');
$('.modal')
.on('show.bs.modal', function () {
nb.width(nb.width());
})
.on('hidden.bs.modal', function () {
nb.width(nb.width('auto'));
});
Fixing the shifting left issue is easily done using CSS alone.
.modal-open[style] {
padding-right: 0px !important;
}
You're just overwriting an inline style that exists in the code. I am using mine in a WordPress build and the inline style was being applied to the body. Looked like this:
<body class="home blog logged-in modal-open" style="padding-right: 15px;">
Hope this helps someone!
$('body').on('show.bs.modal', function () {
if ($("body").innerHeight() > $(window).height()) {
$("body").css("margin-right", "17px");
}
});
$('body').on('hidden.bs.modal', function (e) {
$("body").css("margin-right", "0px");
});
This little fix simulates the scrollbar when the modal is shown, adding a margin-right to the body.
to solve the problem causing the page to shift to the right
html, body{
padding: 0 !important;
}