Bootstrap4:放大主体时的模态渲染问题

Ank*_*cha 1 html javascript css twitter-bootstrap bootstrap-4

我正在尝试使用主体放大为 90% 的 Bootstrap html 页面。Bootstrap 模式显示右侧和底部的空格。为了显示问题,我将主体放大为 90% 的模态的基本 html 页面。

当您单击打开模态时,您将看到模态右侧和底部的空格。我们如何在主体缩放 90% 的情况下渲染没有多余空间的模态。所需的输出是模态模糊背景应覆盖整个屏幕。并且模态主体应该位于 x 轴的中心,就好像 90% 和 100% 的缩放相同,只是 90% 的缩放是小字体

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body style="zoom:90%;">

<div class="container">
  <!-- Button to Open the Modal -->
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
    Open modal
  </button>
  <!-- The Modal -->
  <div class="modal fade" id="myModal">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <!-- Modal body -->
        <div class="modal-body">
          Modal body..
        </div>
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Akb*_*bal 7

.modal-backdrop 类使用 100vh 和 100vw,由于我们应用了 90% 缩放,因此 100vh 对应于屏幕高度的 90%;100vw对应屏幕宽度的90%;

解决方案:重写此类width: 100%; height: 100%;

.modal-backdrop {
  width: 100% !important;
  height: 100% !important;
}
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<body style="zoom:90%;">

  <div class="container">
    <h1> with zoom 90%
    </h1>
    <!-- Button to Open the Modal -->
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
    Open modal
  </button>
    <!-- The Modal -->
    <div class="modal fade" id="myModal">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <!-- Modal body -->
          <div class="modal-body">
            Modal body..
          </div>
          <!-- Modal footer -->
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
Run Code Online (Sandbox Code Playgroud)