Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing the default width of bootstrap modal

I am trying to change the default width of the dialog but it's not working.I have tried solutions mentioned in this post. Here is my HTML code below:

<style>

#myDialog .modal-dialog{

width:80%;

}


</style>


<div id="myDialog" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>
                <div class="modal-title" id="Dialog_title">Text Document</div>
            </div>
            <div class="modal-body">

                <div id="my_doc_content"></div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" onclick="rg.closeDialog('myDialog');">Close</button>
            </div>
        </div>
    </div>
</div>
like image 833
John Avatar asked Aug 08 '16 15:08

John


People also ask

How do I change the default height of a Bootstrap modal box?

modal max-height is 100vh . Then for . modal-body use calc() function to calculate desired height. In above case we want to occupy 80vh of the viewport, reduced by the size of header + footer in pixels.

Which class is used to set the proper width and margin of a modal by default in Bootstrap?

Use the . modal-dialog class in Bootstrap to set the width and margin of the modal.

How do I make my modal responsive screen size?

Modals already fixes the dimensions on mobile to fit the width of the screen, so all you have to do is simply give the big screen/desktop dimensions (500x500 for example) to the plugin code. And modals will be responsive on its own.


2 Answers

Override the .modal-dialog width

.modal-dialog{
   width: 80%;
   margin: auto;
}

Place this piece of code in after the bootstrap.min.css to override its default width.

Here is working fiddle

like image 134
M.Tanzil Avatar answered Oct 02 '22 15:10

M.Tanzil


Here is a JSFiddle that may help you: Working JSFiddle

When CSS style is added on the class .modal instead of .modal-dialog, you can then simply change the width of the modal as you want by the following code:

.modal{
    width: 80%; /* respsonsive width */
    margin-left:-40%; /* width/2) */ 
}

$(function() {
  $("#myDialog").modal("show");
});
.modal-dialog {
  width: 80%;
  margin: auto;
}
.modal{
  width: 80%; /* respsonsive width */
  margin-left:-40%; /* width/2) */ 
}
<div id="myDialog" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>
        <div class="modal-title" id="Dialog_title">Text Document</div>
      </div>
      <div class="modal-body">

        <div id="my_doc_content"></div>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" onclick="rg.closeDialog('myDialog');">Close</button>
      </div>
    </div>
  </div>
</div>

Hope this helps you!

like image 23
Steff Yang Avatar answered Oct 02 '22 15:10

Steff Yang