55
<div class="modal">
  <div class="modal-dialog">
    <div class="modal-content">

      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Modal title</h4>
      </div>

      <div class="modal-body">
        <p>One fine body…</p>
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>

    </div>
  </div>
</div>

how can I change the default modal position in bootstrap, where should I edit to change the default position.

Sonicd300
  • 1,950
  • 1
  • 16
  • 22
dpndra
  • 2,098
  • 4
  • 23
  • 29

8 Answers8

54

Add the following css to your html and try changing the top, right, bottom, left values.

.modal {
   position: absolute;
   top: 10px;
   right: 100px;
   bottom: 0;
   left: 0;
   z-index: 10040;
   overflow: auto;
   overflow-y: auto;
}
msnfreaky
  • 1,013
  • 10
  • 14
19

I get a better result setting this class:

.modal-dialog {
  position: absolute;
  top: 50px;
  right: 100px;
  bottom: 0;
  left: 0;
  z-index: 10040;
  overflow: auto;
  overflow-y: auto;
}

With bootstrap 3.3.7.

(all credits to msnfreaky for the idea...)

Sonicd300
  • 1,950
  • 1
  • 16
  • 22
SanThee
  • 2,301
  • 3
  • 23
  • 35
7

If you need to change the bottom position of the modal, you need to modify the max-height of the modal-body:

.modal-body {
  max-height: 75vh;
}

As other answers have said, you can adjust the right and top on the modal-dialog :

.modal-dialog {
  top: 10vh;
  right: 5vw;
}
  • "vh" means "% of view height"
  • "vw" means "% of view width"
carlin.scott
  • 6,214
  • 3
  • 30
  • 35
6

To change the Modal position in the viewport you can target the Modal div id, in this example this id is myModal3

    <div id="modal3" class="modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body…</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>


#myModal3 {
top:5%;
right:50%;
outline: none;
overflow:hidden;
}
V31
  • 7,626
  • 3
  • 26
  • 44
1

For Bootstrap 5, just add this to your css.

  .modal-dialog { top: 7rem !important; }

Do not add to .modal otherwise the modal will not be dismissed when tapping on the top of the modal because backdrop is shifted down too.

Ken Ratanachai S.
  • 3,307
  • 34
  • 43
1

In the CSS file add following lines:

.modal-dialog {
  transform: translateY(50%)!important;
}

You can change 50% to any other value, which will solve the problem in your browser.

0

In Bootstrap 5 there is two options to open modal in center. No need to add any custom CSS.

  1. Vertically centered modal

<div class="modal-dialog modal-dialog-centered">
  ...
</div>
  1. Vertically centered scrollable modal

<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
  ...
</div>

I hope this will help too.

MShaba007
  • 56
  • 4
-6

I know it's a bit late but I had issues with a modal window not allowing some links on the menu bar to work, even when it has not been triggered. But I solved it by doing the following:

.modal{
display:none;
}