Can someone help me set the width of a bootstrap modal to 75% of the screen's width and horizontally center it? So far I have tried:
<div class="container">
<!-- Modal -->
<div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="createTemplateModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<!--Content-->
<div class="modal-content">
<!--Header-->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel">My Modal</h4>
</div>
<!--Body-->
<div class="modal-body">
<h1>
Modal Body
</h1>
<!--Footer-->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
$('#mymodal').modal('toggle');
$('#mymodal').on('shown.bs.modal', function() {
var width = $(window).width() * 0.75;
console.log('width is: ' + width);
$(this).find(".modal-body").css("width", width);
});
However, this 1) doesn't set the width to 75% of my screen's width and 2) it makes part of the modal body's contents overflow horizontally. Here is my fiddle: http://jsfiddle.net/dc46o5p9/
Thanks in advance!
Bootstrap 4 Modal Change the size of the modal by adding the . modal-sm class for small modals, . modal-lg class for large modals, or . modal-xl for extra large modals.
modal-dialog-centered to . modal-dialog to vertically center the modal.
Example 1: First, we will design modal content for the sign-up then by using CSS we will align that modal centered(vertically). Using the vertical-align property, the vertical-align property sets the vertical alignment of an element.
Change the size of the modal by adding the . modal-sm class for small modals (max-width 300px), . modal-lg class for large modals (max-width 800px), or . modal-xl for extra large modals (max-width 1140px).
Here is the snippet.
$("#mymodal").modal('toggle');
.modal-dialog {
width: 75%;
margin: 0 auto;
}
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet">
<div class="container">
<!-- Modal -->
<div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="createTemplateModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<!--Content-->
<div class="modal-content">
<!--Header-->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel">My Modal</h4>
</div>
<!--Body-->
<div class="modal-body">
<h1>
Modal Body
</h1>
<!--Footer-->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With