I am trying center a modal window in the browser page. I just want to center it, so that it should be responsive for all the screens.
Answer: Use the CSS margin-top Property 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.
Modals use position: fixed , which can sometimes be a bit particular about its rendering. Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You'll likely run into issues when nesting a . modal within another fixed element.
modal-dialog-centered to . modal-dialog to vertically center the modal. This is the best answer for bootstrap 4.
This is the modal styling: const styles = StyleSheet. create({ modal:{ position:"relative", width: 250, height: 100, backgroundColor: '#FFF', justifyContent: 'center', alignSelf: 'center', } }); react-native.
With position:absolute Assuming your modal is 300x300
.modal {
width: 300px;
height: 300px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -150px;
}
With display:table An alternative way for that is to make display table
<div class="modal">
<div class="body">
<div class="content">
Content goes here
</div>
</div>
</div>
<style>
.modal {display:table;}
.body {display:table-cell; vertical-align:middle; text-align:center;}
</style>
Set bootstrap modal center to any size of screen using css only.
.modal {
text-align: center;
padding: 0!important;
}
.modal:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -4px;
}
.modal-dialog {
display: inline-block;
text-align: left;
vertical-align: middle;
}
Browsers & Screens Compatible Solution
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