This question seems to have been asked a number of times on github but I haven't come across any solutions: https://github.com/twitter/bootstrap/issues/1399
how can the modal be vertically aligned properly on small screens?
Answer: Use the CSS margin-top Property But you can align it in the middle of the page vertically using a simple JavaScript trick as described in the example below. 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.
Change the alignment of elements with the vertical-alignment utilities. Please note that vertical-align only affects inline, inline-block, inline-table, and table cell elements. Choose from .align-baseline , .align-top , .align-middle , .align-bottom , .align-text-bottom , and .align-text-top as needed.
One way to vertically center is to use my-auto . This will center the element within it's flexbox container (The Bootstrap 4 . row is display:flex ). For example, h-100 makes the row full height, and my-auto will vertically center the col-sm-12 column.
Edit: As of Bootstrap 2.0.2, this is no longer an issue. Basically, bootstrap now implements the solution proposed below, which I'll leave here for reference purposes.
Generally, on small screens modals will fill out most of your window, so positioning relative to the button that triggered the modal doesn't make terribly much sense. What I usually do is just overwriting the modal position for phones:
@media (max-width: 767px) {
.modal {
top: 20px;
// negative left margin to position horizontally.
margin: 0 0 0 -280px;
// already in modals.less, just copied for clarification:
left: 50%;
position: fixed;
}
}
(This is in LESS, pure CSS solutions looks similar).
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