Left & right align modal footer buttons in Bootstrap 4

后端 未结 9 1149
广开言路
广开言路 2021-01-31 01:21

Bootstrap 4 uses flex-box for it\'s modal footers. If I want two buttons, one on the left and one on the right, how do I get it to work properly?

The code below tries t

相关标签:
9条回答
  • 2021-01-31 01:42

    Totally agree with @Zim and @jmboiton

    If both of these methods are used together, it fixes the issue for everyone (including IE users :P )

    Overall best solution is to combine .justify-content-between and the .mr-auto classes like this:

    <div class="modal-footer justify-content-between">
      <button type="button" class="btn btn-secondary mr-auto" type="button">Left Button</button>
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      <button type="button" class="btn btn-primary">Save changes</button>
    </div>
    

    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
    
    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
      Launch demo modal
    </button>
    
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            ...
          </div>
          <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-secondary mr-auto" type="button">Left Button</button>
              <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>

    0 讨论(0)
  • 2021-01-31 01:52

    The only way it works in IE is using w-100. mx-auto and mr and ml-auto all seems to overflow the buttons from the containing element.

    <div class="modal-footer">
      <div class="w-100">
        <button type="button" class="btn btn-default">Cancel</button>
        <button type="button" class="btn btn-primary float-right">Save</button>
      </div>
    </div>
    
    0 讨论(0)
  • 2021-01-31 01:52

    This is simple and helped me

     <div class="modal-footer">
     <button id="pagePrintBtn" type="button" class="btn btn-primary" style= "float: left;">Print</button>
     </div>
    
    0 讨论(0)
提交回复
热议问题