I have a modal but it's not resizing on smaller screens ( tablets, etc ). Is there a way to make it responsive ? Couldn't find any information on bootstrap docs. Thanks
I update my html code: ( its inside a django for loop )
<div class="modal fade " id="{{ p.id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Producto</h4>
</div>
<div class="modal-body">
<h5>Nombre : {{ p.name}}</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
I have these css settings:
.modal-lg {
max-width: 900px;
}
@media (min-width: 768px) {
.modal-lg {
width: 100%;
}
}
@media (min-width: 992px) {
.modal-lg {
width: 900px;
}
}
This question is related to
html
css
twitter-bootstrap-3
Old post. I ended up setting media queries and using max-width: YYpx;
and width:auto;
for each breakpoint. This will scale w/ images as well (per say you have an image that's 740px width on the md
screen), the modal will scale down to 740px (excluding padding for the .modal-body
, if applied)
<div class="modal fade" id="bs-button-info-modal" tabindex="-1" role="dialog" aria-labelledby="Button Information Modal">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<div class="modal-body"></div>
</div>
</div>
</div>
Note that I'm using SCSS, bootstrap 3.3.7, and did not make any additional edits to the _modals.scss
file that _bootstrap.scss
imports. The CSS below is added to an additional SCSS file and imported AFTER _bootstrap.scss
.
It is also important to note that the original bootstrap styles for .modal-dialog
is not set for the default 992px breakpoint, only as high as the 768px breakpoint (which has a hard set width applied width: 600px;
, hence why I overrode it w/ width: auto;
.
@media (min-width: $screen-sm-min) { // this is the 768px breakpoint
.modal-dialog {
max-width: 600px;
width: auto;
}
}
@media (min-width: $screen-md-min) { // this is the 992px breakpoint
.modal-dialog {
max-width: 800px;
}
}
Example below of modal being responsive with an image.
I had the same problem, and a easy way i found to solve that was to make everything in the modal's body responsive(using boostrap classes) and my problem were solved.
You should be able to adjust the width using the .modal-dialog
class selector (in conjunction with media queries or whatever strategy you're using for responsive design):
.modal-dialog {
width: 400px;
}
From the docs:
Modals have two optional sizes, available via modifier classes to be placed on a .modal-dialog
: modal-lg
and modal-sm
(as of 3.1).
Also the modal dialogue will scale itself on small screens (as of 3.1.1).
Source: Stackoverflow.com