【问题标题】:Bootstrap Carousel with white background during transition from a slide to another从幻灯片过渡到另一张幻灯片期间具有白色背景的引导轮播
【发布时间】:2016-10-27 06:48:39
【问题描述】:

我的 Bootstrap Carousel 出现问题。问题是在使用 css 进行转换期间,一张幻灯片和另一张幻灯片之间的布局。在一秒钟内,仅对一小部分背景,将初始 css 样式重新应用于文本和背景。

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

/*carousel*/
.absolute {
  margin-bottom: -46px;
  text-align: center;
  top: 250px;
  position: relative;
  z-index: 100;
  color: white;
  text-transform: uppercase;
  font-size: 3em;
}
.index .item.active {
  height: 450px;
  background-image: url(images/first-back.jpg);
  background-position: 0 5%;
  background-repeat: no-repeat;
  background-size: cover;
  background-color: rgba(51, 51, 51, 0.34);
  background-blend-mode: multiply;
}
.carousel-inner .item:nth-child(2) {
  background: url(images/ac-bottom.jpg);
  height: 450px;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: 0 52%;
  background-color: rgba(51, 51, 51, 0.34);
  background-blend-mode: multiply;
}
.carousel-inner .item:nth-child(3) {
  background: url(images/grills-slider.jpg);
  height: 450px;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: 0 52%;
  background-color: rgba(51, 51, 51, 0.34);
  background-blend-mode: multiply;
}
.carousel-inner .item:nth-child(4) {
  background: url(images/store.jpg);
  height: 450px;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: 0 52%;
  background-color: rgba(51, 51, 51, 0.34);
  background-blend-mode: multiply;
}
.index .item:nth-child(4) h1 {
  text-decoration: underline;
}
.item.active h1 {
  font-size: 2em;
  color: white;
  text-align: center;
  position: relative;
  top: 66%;
  text-transform: uppercase;
}
<div id="myCarousel" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <h1>Is relaxing</h1>
    </div>
    <div class="item">
      <h1>IS PEACE OF MIND</h1>
    </div>
    <div class="item">
      <h1>IS CONFIDENCE</h1>
    </div>
    <div class="item">
      <h1>STARTS HERE</h1>
    </div>
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

如您所见,我在 html 中使用的是背景图片而不是普通标签。最后一件事,我在轮播外使用h1

<h1 class="absolute">COMFORT</h1>

这将保持固定,用于布局目的。

提前谢谢你

【问题讨论】:

    标签: css twitter-bootstrap-3 css-transitions carousel


    【解决方案1】:

    UPD。避免使用.active 类进行装饰。此类提供幻灯片之间的过渡。你可以看到.carousel-inner &gt; .item.active.carousel-inner &gt; .activebootstrap.css 中定义。

    请检查新代码。是你想要达到的吗?

    @import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
    
    .carousel-inner {
      margin-top: 2%;
    }
    
    .carousel-inner .item {
      height: 450px;
      background-image: url(//placehold.it/600x200/69c/def/?text=first);
      background-size: cover;
      background-repeat: no-repeat;
      background-position: 0% 52%;
      background-color: rgba(51, 51, 51, 0.34);
      background-blend-mode: multiply;
    }
    .carousel-inner .item:nth-child(2) {
      background-image: url(//placehold.it/600x200/9c6/efd/?text=second);
    }
    .carousel-inner .item:nth-child(3) {
      background-image: url(//placehold.it/600x200/c69/fde/?text=third);
    }
    .carousel-inner .item:nth-child(4) {
      background-image: url(//placehold.it/600x200/96c/edf/?text=fourth);
    }
    
    .carousel-inner .item h1 {
      color: white;
      font-size: 2em;
      text-align: center;
      text-transform: uppercase;
      
      position: absolute;
      top: 60%;
      left: 0;
      right: 0;
    }
    .carousel-inner .item:nth-child(4) h1 {
      text-decoration: underline;
    }
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner" role="listbox">
        <div class="item active">
          <h1>Is relaxing</h1>
        </div>
        <div class="item">
          <h1>Is peace of mind</h1>
        </div>
        <div class="item">
          <h1>Is confidence</h1>
        </div>
        <div class="item">
          <h1>Starts here</h1>
        </div>
      </div>
    </div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

    【讨论】:

    • 不幸的是,两张幻灯片之间有一个奇怪的效果,这意味着它会出现一秒钟的白色背景的 h1 元素(h1 没有定位,所以它在页面的顶部) 并在几秒钟后出现正确的格式。你知道它为什么会发生吗?
    • @MarcoMaffei 避免使用.active 类进行装饰。此类提供幻灯片之间的过渡。您可以看到.carousel-inner &gt; .item.active.carousel-inner &gt; .activebootstrap.css 中是如何定义的。
    • 这实际上是一个非常好的建议。避免总是 .active 或所有其他引导类,对吧?
    • @MarcoMaffei 当您更改任何 Bootstrap 类时,您已经更改了某些 Bootstrap 组件的行为。如果您了解后果,您可以这样做。
    【解决方案2】:

    确实是因为我添加了几行其他代码(css 样式)来设置我代码中的模块(javascript 模块)的样式。这种风格包含两个类(右和左) .right 和 .left ,它们干扰了我的风格(引导轮播将类右和左添加到轮播的每张幻灯片)。问题解决了!

    【讨论】:

      【解决方案3】:

      如果过渡期间幻灯片之间出现空白,您可能需要尝试更改 Twitter 引导代码 .carousel-inner { overflow: hidden; } to .carousel-inner { 溢出:可见; }。

      【讨论】:

        【解决方案4】:

        需要从隐藏改为可见

        .carousel-inner { 
            overflow: visible; 
        }
        

        然后添加到body标签

        overflow-x: hidden;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-12-26
          • 2021-01-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多