Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap modal removes scroll bar

When I trigger a modal view in my page it triggers the scroll bar to disappear. It's an annoying effect because the background page starts moving when the modal moves in / disappears. Is there a cure for that effect?

like image 701
El Dude Avatar asked Jul 31 '14 22:07

El Dude


People also ask

How do I enable scrolling in modal?

Use the . modal-dialog-scrollable class to enable scrolling inside the modal.

How do I add a scroll bar to my modal?

Bootstrap 4.3 added new built-in scroll feature to modals. This makes only the modal-body content scroll if the size of the content would otherwise make the page scroll. To use it, just add the class modal-dialog-scrollable to the same div that has the modal-dialog class.

How do I disable scrolling when modal is open?

Approach: A simple solution to this problem is to set the value of the “overflow” property of the body element to “hidden” whenever the modal is opened, which disables the scroll on the selected element.

Why bootstrap modal is not working in react?

The issue was not because of "react-bootstrap" package. The issue is: you must have imported bootstrap css and bootstrap css in react-bootstrap package are clashing. Try importing css as follows: import "bootstrap/dist/css/bootstrap.


2 Answers

This is a feature, class modal-open gets added to the HTML body when you show the modal, and removed when you hide it.

This makes the scrollbar disappear since the bootstrap css says

.modal-open {     overflow: hidden; } 

You can override this by specifying

.modal-open {     overflow: scroll; } 

in your own css.

like image 80
flup Avatar answered Sep 28 '22 03:09

flup


I think that inherit is better than scroll because when you open modal, it will always open with scroll, but when you don't have any scrolls you will get the same problem. So I just do this:

.modal-open {   overflow: inherit; } 
like image 28
Alisson Alvarenga Avatar answered Sep 28 '22 05:09

Alisson Alvarenga