I am working on a project in which there are multiple Bootstrap modal’s of different sizes. I want to change the position of all the modal at one specific point on the screen.
I am attaching sample code in which there are 3 modals of different sizes. Modal 1 opens at proper position because i have overridden the default position properties,but the other two modal i.e. 2 and 3 are not opening at that point.
One solution is that i assign all modals a different ID and then position each modal via css but that would lead to inconsistency in design. I am unable to find common solution.
NOTE
I have more than 500 modal all are of different size i don’t want to specify position of each modal. Is there anything i can dynamically capture screen size/modal size and align my modal to one single point
.modal {
top: 21px;
left: -290px;
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal1">Modal 1</button>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal2">Modal 2</button>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal3">Modal 3</button>
<!-- MODAL 1 -->
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal 1</h4>
</div>
<div class="modal-body">
<p>This is Default Size Modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- MODAL 2 -->
<div id="myModal2" class="modal fade" role="dialog">
<div class="modal-dialog" style="width:20%">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal 2</h4>
</div>
<div class="modal-body">
<p>This is small Modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- MODAL 3 -->
<div id="myModal3" class="modal fade" role="dialog">
<div class="modal-dialog" style="width:90% !important; max-width:100% !important;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal 3</h4>
</div>
<div class="modal-body">
<p>This is Big Modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
4
Answers
here you have a link
https://codepen.io/kalaiselvan/pen/oWRrva
you can able to open dynamically open model by size using common function by passing size of a modal
I would use data attributes to define my modal position, or maybe my modal class which might seems better, in my example i use positions, but i would suggest you use predefined classes, the same way
example
Remember to use
!important
CSS declarations as below, if you want to forcibly use the styles on all instances of.modal
:Note: this will look terrible until appropriate CSS has been added which suitable for all modal dialogues, but the idea is that the CSS is being applied to all instances.
I found this simple jS solution