How can I centralize a Bootstrap V4 modal with CSS?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
This question already has answers here:
Closed 2 years ago.
回答1:
You can vertical center the modal by overriding the position of the .modal-dialog
like this..
.modal.show .modal-dialog {
-webkit-transform: translate(0,-50%);
-o-transform: translate(0,-50%);
transform: translate(0,-50%);
top: 50%;
margin: 0 auto;
}
http://www.codeply.com/go/14Ki1kyTgo
Update 2018
As of Bootstrap 4 Beta 3, there is a new modal-dialog-centered
class that can be used instead of the custom method described above.
https://www.codeply.com/go/lpOtIFoN6E (Beta 3)
回答2:
Using Flexbox its really easy to add vertical align bootstrap 4 modal popup. Here's the CSS Code.
See Woking Demo
SASS
.modal-open .modal.modal-center {
display: flex!important;
align-items: center!important;
.modal-dialog {
flex-grow: 1;
}
}
Compiled CSS
.modal-open .modal.modal-center {
display: -webkit-box !important;
display: -ms-flexbox !important;
display: flex !important;
-webkit-box-align: center !important;
-ms-flex-align: center !important;
align-items: center !important;
}
.modal-open .modal.modal-center .modal-dialog {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
}
See Woking Demo