简体   繁体   English

Center Bootstrap 5 模态水平

[英]Center Bootstrap 5 Modal horizontal

In my vue application, Bootstrap 5 modal is not centered horizontally in desktop.在我的 vue 应用程序中,Bootstrap 5 modal 不在桌面水平居中。 This is my component:这是我的组件:

Modal.vue模态的.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>

I checked with inspecting elements but didn't find the way.我检查了检查元素,但没有找到方法。 the HTML structure is copied from getbootstrap.com and everything is working great in mobile . HTML 结构是从 getbootstrap.com 复制的,并且在移动设备中一切正常。

在此处输入图像描述

With this line有了这条线

margin: 20px !important;

You delete the auto property to center the modal.您删除auto属性以使模态居中。

Use this instead改用这个

margin: 20px auto !important;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM