Bootstrap 模态页脚按钮全宽

Bootstrap Modal Footer Button Full Width

我正在尝试将“关闭”按钮居中并展开至其全宽: https://i.stack.imgur.com/ogBsV.png

到目前为止的代码:

<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>

谢谢

Bootstrap-5 不再像 Bootstrap 4 曾经有的 btn-block (Documentation)。它现在由 grid/flex 控制。在您的代码中, modal-footer class 默认情况下已经是一个 flex。因此,您需要做的就是将 class col-12(或任何其他值,如果您想更改宽度)添加到 按钮 。它会变成一个块按钮。

<!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>