如何正确中心 Bootstrap 宽模态?

trnvg8h3  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(1)|浏览(138)

在移动的设备上,当正文最小宽度大于980px时,Bootstrap模态不能正确居中。
我尝试了bootstrap 4、bootstrap 5和bootstrap 3模态。
您可以在屏幕截图中看到,模态div位于屏幕之外,背景没有覆盖整个宽度,在右侧留下白色。

<!DOCTYPE html>
<html dir="rtl">

<head>

  <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
    integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
    crossorigin="anonymous"></script>

  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
    integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

  <!-- Latest compiled and minified JavaScript -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
    integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
    crossorigin="anonymous"></script>

</head>

<body>
  <style>
    body {
      min-width: 1035px;
    }
  </style>

  <button class="btn btn-lg btn-primary center-block text-" data-remote="false" data-toggle="modal"
    data-target="#myModal">show modal</button>

  <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-label="Close"><span
              aria-hidden="true">&times;</span></button>
        </div>
        <div class="modal-body">
          some content
        </div>
      </div>
    </div>
  </div>

</body>

</html>
5n0oy7gb

5n0oy7gb1#

像class=“modal fade mx-auto”那样将mx-auto类添加到父div

相关问题