javascript - Bootstrap 4 : modal rendering issue with zoomed in body

标签 javascript html css twitter-bootstrap bootstrap-4

我正在尝试使用主体放大 90% 的 Bootstrap html 页面。Bootstrap 模式显示右侧和底部的空格。 为了显示这个问题,我在 body 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>

最佳答案

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

解决方案:用width: 100%覆盖这个类;高度:100%;

.modal-backdrop {
  width: 100% !important;
  height: 100% !important;
}
<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>

关于javascript - Bootstrap 4 : modal rendering issue with zoomed in body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55988523/

相关文章:

javascript - meteorjs用户权限未与服务器同步

html - 仅删除输入元素上的一个边框而不影响其他边框

html - Off-Canvas 菜单使得页脚不可见

html - 容器的 flexbox 元素不保持其长度

html - CSS内联 block 宽度问题

javascript - 本地图很小时,如何使 Google map 中的版权文本换行?

javascript - 错误 : Conflict: Constraint universe:modules@0. 6.4 不满足 Universe :modules 0. 1.0

html - 居中动画始终偏离中心

javascript - Vue 资源 $http 未定义

javascript - 使用 JavaScript 和 HTML 打印表情符号