Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter bootstrap scrollable modal

I'm using twitter bootstrap for a project I am working on.

I have a modal window that has a somewhat longer form in it and I didn't like that when the window got too small the modal didn't scroll (if just disappeared off my page which isn't scrollable).

To fix this I used the following css

.modal {     overflow-y:auto;     max-height:90%;     margin-top:-45%; } 

This works exactly the way I want it to in Chrome (that is, the form is full size when the window is big enough, but as the window shrinks the modal shrinks and becomes scrollable). The problem is that in IE the modal is off the screen. Does anyone have a better solution to this problem?

My example can be found at tinyhousemap.com (click 'Add an Entry to the map' in the navigation window for the modal to appear)

Thanks

like image 999
Dan dot net Avatar asked Mar 28 '12 00:03

Dan dot net


People also ask

How do I make a Bootstrap modal scrollable?

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.

What is data BS dismiss?

The .modal-header class is used to define the style for the header of the modal. The <button> inside the header has a data-dismiss="modal" attribute which closes the modal if you click on it.

How do I stop my modal from closing when I click outside?

When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.

How can I show data using a modal when clicking a table row using Bootstrap )?

On each of your <tr> 's add a data attribute for id (i.e. data-id ) with the corresponding id value and specify a data-target , which is a selector you specify, so that when clicked, bootstrap will select that element as modal dialog and show it.


1 Answers

How about the below solution? It worked for me. Try this:

.modal .modal-body {     max-height: 420px;     overflow-y: auto; } 

Details:

  1. remove overflow-y: auto; or overflow: auto; from .modal class (important)
  2. remove max-height: 400px; from .modal class (important)
  3. Add max-height: 400px; to .modal .modal-body (or what ever, can be 420px or less, but would not go more than 450px)
  4. Add overflow-y: auto; to .modal .modal-body

Done, only body will scroll.

like image 117
Lijana Saniukaite Avatar answered Oct 20 '22 03:10

Lijana Saniukaite