HTML CSS examples for Bootstrap:Modal
Align Modal Dialog Vertically Center
<!DOCTYPE html> <html> <head> <title>Center Align Bootstrap Modal Vertically</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ function alignModal(){<!-- ww w .j a va 2 s . com--> var modalDialog = $(this).find(".modal-dialog"); modalDialog.css("margin-top", Math.max(0, ($(window).height() - modalDialog.height()) / 2)); } $(".modal").on("shown.bs.modal", alignModal); $(window).on("resize", function(){ $(".modal:visible").each(alignModal); }); }); </script> </head> <body> <div> <a href="#myModal" class="btn btn-lg btn-primary" data-toggle="modal">Launch Demo Modal</a> <div id="myModal" class="modal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Confirmation</h4> </div> <div class="modal-body"> <p>Do you want to save changes you made to document before closing?</p> <p class="text-warning"><small>If you don't save, your changes will be lost.</small></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div> </div> </body> </html>