How can I change the default width of a Twitter Bootstrap modal box?

后端 未结 30 2467
醉酒成梦
醉酒成梦 2020-11-27 08:38

I tried the following:

   
相关标签:
30条回答
  • 2020-11-27 09:17

    Bootstrap 3: In order to maintain responsive features for small and extra small devices I did the following:

    @media (min-width: 768px) {
    .modal-dialog-wide
    { width: 750px;/* your width */ }
    }
    
    0 讨论(0)
  • 2020-11-27 09:17

    This is what I did, in my custom.css I added these lines and that was all.

    .modal-lg {
        width: 600px!important;
        margin: 0 auto;
    }
    

    Obviously, you can change the size of the width.

    0 讨论(0)
  • 2020-11-27 09:17

    I used SCSS, and the fully responsive modal:

    .modal-dialog.large {
        @media (min-width: $screen-sm-min) { width:500px; }
        @media (min-width: $screen-md-min) { width:700px; }
        @media (min-width: $screen-lg-min) { width:850px; }
    } 
    
    0 讨论(0)
  • 2020-11-27 09:18

    If Bootstrap>3, Just add style to your modal.

    <div class="modal-dialog" style="width:80%;">
      <div class="modal-content">
      </div>
    </div>
    
    0 讨论(0)
  • 2020-11-27 09:20

    If you're using Bootstrap 3, you need to change the modal-dialog div and not the modal div like it is shown in the accepted answer. Also, to keep the responsive nature of Bootstrap 3, it's important to write the override CSS using a media query so the modal will be full width on smaller devices.

    See this JSFiddle to experiment with different widths.

    HTML

    <div class="modal fade">
        <div class="modal-dialog custom-class">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h3 class="modal-header-text">Text</h3>
                </div>
                <div class="modal-body">
                    This is some text.
                </div>
                <div class="modal-footer">
                    This is some text.
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    

    CSS

    @media screen and (min-width: 768px) {
        .custom-class {
            width: 70%; /* either % (e.g. 60%) or px (400px) */
        }
    }
    
    0 讨论(0)
  • 2020-11-27 09:20

    I used this way, and it's work perfect for me

    $("#my-modal")
    .modal("toggle")
    .css({'width': '80%', 'margin-left':'auto', 'margin-right':'auto', 'left':'10%'});
    
    0 讨论(0)
提交回复
热议问题