Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center modal to the center of screen?

How to center modal to the center of screen? This is my html and js code It works in Chrome console, but when I refresh this page - it doesn't work

$('.modal').css('top', $(window).outerHeight() / 2 - ($(".modal-dialog").outerHeight()) / 2 + 'px'); 
like image 831
Vlad Udod Avatar asked Sep 21 '16 22:09

Vlad Udod


People also ask

How do I center my modal in the middle of my screen?

In this example first, use the find() method to find out the modal dialog. Then subtract the modal height from the window height and divide that into half and will place the modal that will be the centered(vertically). This solution will dynamically adjust the alignment of the modal.

How do I show model in center?

display: block; max-width: 100%; height: auto; display:block means text-align:centre which is inherited from text-center will have no effect. If you remove the . img-responsive class, your image will be centred.

How do I center a bootstrap modal?

Answer: Use the CSS margin-top Property This solution will dynamically adjust the alignment of the modal and always keep it in the center of the page even if the user resizes the browser window.


1 Answers

Easy way to solve

.center {   position: absolute;   left: 50%;   top: 50%;   transform: translate(-50%, -50%); } 
like image 161
Vlad Udod Avatar answered Sep 22 '22 11:09

Vlad Udod