Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

413
Views
Center Bootstrap 5 Modal horizontal

In my vue application, Bootstrap 5 modal is not centered horizontally in desktop. This is my component:

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>

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.

enter image description here

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

With this line

margin: 20px !important;

You delete the auto property to center the modal.

Use this instead

margin: 20px auto !important;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!