Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to increase bootstrap modal's height

I am trying to find a workaround for increasing the height of my bootstrap modal. I did try the maximum fix way in the modal body, but that just cuts off my modal if it goes oversize. I am trying to find a way to make it work like how modals work on pinterest.

I have already disabled the main page body scrolling when the modal is open. But I am having troubles with adjusting the size.

Does anyone have any work arounds for that?

I tried adding height to my modal (height:95%;) and modal_body (max-height: 75%;), the content overflows out of the parent div (modal)

I've attached a screenshot to demonstrate the same

Screenshot

Update

I ended up making my own modal with the pintrest kind of attributes. this question helped me alot with it

like image 708
Jonathan Avatar asked Dec 23 '12 06:12

Jonathan


People also ask

How do you change the height of a modal body?

modal-body use calc() function to calculate desired height. In above case we want to occupy 80vh of the viewport, reduced by the size of header + footer in pixels. This is around 140px together but you can measure it easily and apply your own custom values. For smaller/taller modal modify 80vh accordingly.

How do I resize react modal?

The Dialog supports resizing feature. To resize the dialog, we have to select and resize it by using its handle (grip) or hovering on any of the edges or borders of the dialog within the sample container.

Which of the following class in Bootstrap is used for creating the small size modal?

Which of the following class in Bootstrap is used for creating the small size modals? Answer : . modal-sm.

How do I minimize modal popups?

To implement a responsible popup that can be minimized to the bottom of the page: Set the Top and Left parameters to control the position of the modal. Use boolean flags to show and hide the popup. Use the MediaQuery component to make the modal window responsive.


3 Answers

Try with this js to calculate the modal height:

$(document).ready(function() {
    $(".showcomments").click(function() {
        $('#myModal').modal('show');
        rescale();
    });
    $("[rel=tooltip]").tooltip();
});
function rescale(){
    var size = {width: $(window).width() , height: $(window).height() }
    /*CALCULATE SIZE*/
    var offset = 20;
    var offsetBody = 150;
    $('#myModal').css('height', size.height - offset );
    $('.modal-body').css('height', size.height - (offset + offsetBody));
    $('#myModal').css('top', 0);
}
$(window).bind("resize", rescale);

Test: http://jsfiddle.net/fUZxA/23/

like image 190
karacas Avatar answered Oct 07 '22 23:10

karacas


It worked for me just fine by using this CSS:

.my-modal {
  width:600px;
  height:300px;

  .modal-header {
    background-color:#ccc;
    button {
      font-size:30px;
    }
  }
  .modal-body {
    overflow-y: hidden;
    height: 100%;
    max-height:190px;
  }

}

Update: I took a look at your fiddle. Try to add "height" to your modal.

like image 20
Paola Cerioli Avatar answered Oct 07 '22 23:10

Paola Cerioli


The bootstrap modal opens in position: fixed. This way it will always stay on the same place no matter how much u scroll. So a part of it you might not see. If you want to see the rest of the modal you need to make it position: absolute. But the problem with this is it will always go to the top of the page. But I have a fix for this if you want to know

like image 1
Chanckjh Avatar answered Oct 07 '22 23:10

Chanckjh