以旋转木马模态为中心

时间:2018-03-19 17:18:44

标签: css twitter-bootstrap bootstrap-4

我为Bootstrap创建了一个旋转木马模态,无论屏幕尺寸如何,或者例如移动屏幕垂直倾斜,我都无法弄清楚如何正确居中。

我现在拥有的CSS代码正确地将模态放在普通的电脑屏幕上,但它在移动屏幕上不起作用,并且MOdal出现在屏幕的顶部而不是出现在它应该的中间。

position

,也不     垂直对齐 为我工作。



.modal {
  vertical-align: middle;
  padding-left: 5%;
  padding-left: 5%;
  padding-top: 1%;
  text-align: middle;
  max-height: 90vh;
  max-width: 95vw;
}

.modal .carousel-inner {
  max-height: 100% ! important;
  position: center;
  text-align: middle;
  vertical-align: middle;
}

.modal .carousel .item @media (max-width: 991px) {
  .modal {
    padding-top: 55%;
  }
}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<!-- Page Content -->
<div class="container">

  <h1 class="my-4 text-center text-lg-left" style="padding-bottom:3%;padding-left:0%">Gallerie</h1>
  <div class="row text-center text-lg-left">

    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="" data-toggle="modal" data-target="#Gallerie">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
    <div class="col-lg-3 col-md-4 col-xs-6">
      <a href="#" class="d-block mb-4 h-100">
        <img class="img-fluid img-thumbnail" src="http://placehold.it/400x300" alt="">
      </a>
    </div>
  </div>
  <div class="modal" id="Gallerie">
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner">
        <div class="carousel-item active">
          <img class="d-block w-100" src="http://placehold.it/400x300" alt="First slide">
        </div>
        <div class="carousel-item">
          <img class="d-block w-100" src="http://placehold.it/400x300" alt="Second slide">
        </div>
        <div class="carousel-item">
          <img class="d-block w-100" src="http://placehold.it/400x300" alt="Third slide">
        </div>
      </div>
      <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
  </div>
</div>

<!--/Gallerie-->
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

模态需要正确的结构Bootstrap 4 docs。只需使用 $supplier.done ,您就不需要额外的CSS ......

https://www.codeply.com/go/BDNba719xE

modal-dialog-centered