html - Center Bootstrap 5 模态水平

标签 html css twitter-bootstrap vue.js bootstrap-modal

在我的 vue 应用程序中,Bootstrap 5 模态没有在桌面水平居中。 这是我的组件:

Modal.vue

<template>
  <teleport to="#modal-container">
    <div
      ref="modalRef"
      class="modal fade"
      :id="`modal-${id}`"
      tabindex="-1"
      :aria-labelledby="`modal-${id}`"
      aria-hidden="true"
    >
      <div class="modal-dialog modal-dialog-centered">
        <div
          class="modal-content"
          :style="[noPadding && { backgroundColor: 'transparent' }]"
        >
          <div v-if="!noHeader" class="modal-header">
            <slot name="header" />
          </div>
          <div class="modal-body" :style="[noPadding && { padding: 0 }]">
            <slot />
          </div>
        </div>
      </div>
    </div>
  </teleport>
</template>

<script lang="ts">
import {
  defineComponent,
  onMounted,
  ref,
  watch,
  getCurrentInstance,
} from "vue";
import { Modal } from "bootstrap";
import { onBeforeRouteLeave } from "vue-router";

export default defineComponent({
  name: "Modal",
  // modal states logic, no styles ....
});
</script>

<style lang="scss">
.modal-dialog {
  margin: 20px !important;

  .modal-header {
    font-weight: 500;
    font-size: 17px;
    border-bottom: none;
    color: $dark;
    padding-bottom: 0;
  }

  .modal-content {
    border-radius: 10px;
  }
}
</style>

我检查了检查元素,但没有找到方法。 HTML 结构是从 getbootstrap.com 复制的,在 mobile 中一切正常。

enter image description here

最佳答案

用这条线

margin: 20px !important;

您删除 auto 属性以使模态居中。

改用这个

margin: 20px auto !important;

关于html - Center Bootstrap 5 模态水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70276245/

相关文章:

jquery dataTables - 如何提取行数据 onclick 事件

c++ - 使用 C++ 创建 HTML 报告

html - 每行 3 行的简单 css 不起作用

android - 粘性页脚问题(Android、Apple IOS)

html - IE 检测内联样式的速度不够快

jQuery.倒计时样式

javascript - 尽管刷新,jQuery 格式仍不适用于 ajax 数据

html - CSS 与 IE8 的兼容性问题

jquery - 打包 jquery 和 bootstrap

css - 当 li 具有不同的宽度时,如何使它们具有相同的高度(响应式)?