How can I change the width of a Bootstrap 3 modal in IE8?

前端 未结 6 1121
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 19:47

I have to support IE8. The modal itself works fine, but my attempts to resize it (which work fine in Firefox) don\'t work in IE8.

I\'m just adding a class (wide-mod

相关标签:
6条回答
  • 2020-12-29 20:23

    I know it is late but just found in bs3 docs you can add modal-lg class to your modals

    <!-- Large modal -->
    <button class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">
      Large modal
    </button>
    
    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
         ...
        </div>
      </div>
    </div>
    
    <!-- Small modal -->
    <button class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">
      Small modal
    </button>
    
    <div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
     <div class="modal-dialog modal-sm">
       <div class="modal-content">
         ...
       </div>
     </div>
    </div>
    
    0 讨论(0)
  • 2020-12-29 20:23

    This will of course change the width for all of your modal windows, but it might give you a better idea on how this works. I just changed my modal windows this way.

        .modal-body {
            position: relative;
            padding: 20px;
            min-width: 800px; /* SET THE WIDTH OF THE MODAL */
        }
    
        .modal-content {
            position: relative;
            background-color: #fff;
            border: 1px solid #999;
            border: 1px solid rgba(0,0,0,0.2);
            border-radius: 6px;
            outline: 0;
            -webkit-box-shadow: 0 3px 9px rgba(0,0,0,0.5);
            box-shadow: 0 3px 9px rgba(0,0,0,0.5);
            background-clip: padding-box;
            width: 900px; /* SET THE WIDTH OF THE MODAL */
            margin: 50px 0 0 -150px; /* CHANGE MARGINS TO ACCOMMODATE THE NEW WIDTH */
        }
    
    
    
    <!-- Button trigger modal -->
      <a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Launch demo modal</a>
    
      <!-- Modal -->
      <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title">Modal title</h4>
            </div>
            <div class="modal-body">
              ...
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="button" class="btn btn-primary">Save changes</button>
            </div>
          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
      </div><!-- /.modal -->
    
    0 讨论(0)
  • 2020-12-29 20:29
    #modalTest.modal-dialog{
        width: <insert size> !important;
    }
    the !important is important :v
    
    0 讨论(0)
  • 2020-12-29 20:31

    In bootstrap 3 you need assign width not to .modal class but to .modal-dialog

    #modalTest .modal-dialog
    {
        width: 500px; /* your width */
    }
    
    0 讨论(0)
  • 2020-12-29 20:37

    I think you need to set the width in pixels and adjust the margin-left. For example,

    .modal-dialog {
        width:700px;
        margin-left:-320px;
    }
    

    The margin left must be half the width of the modal, minus 30px for the scrollbar.

    Here's an example on Bootply: http://bootply.com/85213

    0 讨论(0)
  • 2020-12-29 20:40

    I used a combination of CSS and jQuery, along with hints on this page, to create a fluid width and height using Bootstrap 3. I also tested this on IE8 on Win7, and it works great.

    First, some CSS to handle the width and optional scrollbar for the content area

    .modal.modal-wide .modal-dialog {
      width: 90%;
    }
    .modal-wide .modal-body {
      overflow-y: auto;
    }
    

    And then some jQuery to adjust the height of the content area if needed

    $(".modal-wide").on("show.bs.modal", function() {
      var height = $(window).height() - 200;
      $(this).find(".modal-body").css("max-height", height);
    });
    

    Full write-up and code at http://scottpdawson.com/development/creating-a-variable-width-modal-dialog-using-bootstrap-3/

    0 讨论(0)
提交回复
热议问题