I'm trying to fit a lot of text into a modal box created using Twitter Bootstrap but I'm having a problem: the content refuses to scroll. I tried adding overflow:scroll
and overflow-y:scroll
but to no avail; that merely causes it to display a scroll-bar without actually enabling scrolling.
What's the cause behind that and what can I do?
Actually for Bootstrap 3 you also need to override the .modal-open class on body.
In Bootstrap 3 you have to change the
css
class.modal
before (bootstrap default) :
after (after you edit it):
In Bootstrap.css change the background attribute (
position
) of Modal fromfixed
toabsolute
Bootstrap will add or remove a css
"modal-open"
to the<body>
tag when we open or close a modal. So if you open multiple modal and then close arbitrary one, the modal-open css will be removed from the body tag.But the scroll effect depend on the attribute
"overflow-y: auto;"
defined inmodal-open
When using Bootstrap modal with skrollr, the modal will become not scrollable.
Problem fixed with stop the touch event from propagating.
more details at Add scroll event to the element inside #skrollr-body
If I recall correctly, setting overflow:hidden on the body didn't work on all the browsers I was testing for a modal library I built for a mobile site. Specifically, I had trouble with preventing the body from scrolling in addition to the modal scrolling even when I put overflow:hidden on the body.
For my current site, I ended up doing something like this. It basically just stores your current scroll position in addition to setting "overflow" to "hidden" on the page body, then restores the scroll position after the modal closes. There's a condition in there for when another bootstrap modal opens while one is already active. Otherwise, the rest of the code should be self explanatory. Note that if the overflow:hidden on the body doesn't prevent the window from scrolling for a given browser, this at least sets the original scroll location back upon exit.
If you don't like this, the other option would be to assign a max-height and overflow:auto to .modal-body like so:
For this case, you could configure the max-height for different screen sizes and leave the overflow:auto for different screen sizes. You would have to make sure that the modal header, footer, and body don't add up to more than the screen size, though, so I would include that part in your calculations.