代码之家  ›  专栏  ›  技术社区  ›  Natalie Perret

Bootstrap v4:滑动完成时,仅文本转盘仅居中文本(否则粘贴到顶部)

  •  0
  • Natalie Perret  · 技术社区  · 6 年前

    你知道为什么这个纯文本旋转木马(Bootstrap v4)将我的旋转木马项目文本粘贴到顶部,然后将其居中对齐,而不是直接正确对齐项目的文本吗?

    <div id="myTextOnlyCarousel" class="carousel slide mt-5" data-ride="carousel">
      <ol class="carousel-indicators">
        <li data-target="#myTextOnlyCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myTextOnlyCarousel" data-slide-to="1"></li>
        <li data-target="#myTextOnlyCarousel" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner bg-dark text-light rounded text-center d-flex h-100 align-items-center justify-content-center" style="min-height: 300px;">
        <div class="carousel-item active">
          <h1>This is AWESOME!</h1>
        </div>
        <div class="carousel-item">
          <h1>This is freaking AMAZING!</h1>
        </div>
        <div class="carousel-item">
          <h1>YEAHHH</h1>
        </div>
      </div>
      <a class="carousel-control-prev" href="#myTextOnlyCarousel" 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="#myTextOnlyCarousel" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   MontyGoldy    6 年前

    好的,这是因为carousel item类上的活动类,这就是在动画中进行文本幻灯片的原因。因此,将其更改为“显示块”,并添加“从旋转木马中移除flex”。

    .carousel-item .text{
      display: flex;
      height: 100%!important;
      min-height: 300px;
      align-items: center;
      justify-content: center;
    }
    
    .carousel-item.active,
    .carousel-item-next,
    .carousel-item-prev{
        display:block;
    }
    <div id="myTextOnlyCarousel" class="carousel slide mt-5" data-ride="carousel">
      <ol class="carousel-indicators">
        <li data-target="#myTextOnlyCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myTextOnlyCarousel" data-slide-to="1"></li>
        <li data-target="#myTextOnlyCarousel" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner bg-dark text-light rounded text-center  h-100  " style="min-height: 300px;background: red;">
        <div class="carousel-item active">
          <div class="text">
            <h1>This is AWESOME!</h1>
          </div>
        </div>
        <div class="carousel-item">
          <div class="text">
            <h1>This is freaking AMAZING!</h1>
          </div>
        </div>
        <div class="carousel-item">
          <div class="text">
            <h1>YEAHHH</h1>
          </div>
        </div>
    
      </div>
      <a class="carousel-control-prev" href="#myTextOnlyCarousel" 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="#myTextOnlyCarousel" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
        2
  •  0
  •   Gautam Naik    6 年前

    这是我的解决方案 JSFiddle

    我强奸了你 h1 用一个 wrapper

    我不得不放弃 最小高度 因为如果没有它,这些物品会粘在最上面。

    .wrapper {
      min-height:300px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    

    并删除了一些应用于 .carousel-inner div