Search code examples
bootstrap-modal

Bootstrap Modal Footer Button Full Width


im trying to center and expand the "Close" button to its full width: https://i.sstatic.net/ogBsV.png

Code so far:

<div class="modal-dialog">
 <div class="modal-content">
    <div class="modal-header">
        <h5 class="modal-title modalHeading" id="ariaangebote">Title</h5>
    </div>
    <div class="modal-body">
    </div>
    <div class="modal-footer">
        <button type="button" class="btn mainBtn btn-block" data-bs-dismiss="modal">
            Close
        </button>
    </div>
</div>

Thank you


Solution

  • Bootstrap-5 doesn't have btn-block anymore like Bootstrap 4 used to (Documentation). Its now controlled with grid/flex. In your code, modal-footer class is already a flex by default. So all you need do to is add the class col-12 (or any other value if you want to change the width) to the button. It'll become a block button.

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    </head>
    
    <body>
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title modalHeading" id="ariaangebote">Title</h5>
          </div>
          <div class="modal-body">
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-primary col" data-bs-dismiss="modal">
                Close
              </button>
          </div>
        </div>
      </div>
    
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    </body>
    
    </html>