我正在使用带有三张幻灯片的基本Bootstrap旋转木马。在我实现滑块之前,我有一个静态图像通过其各自的div的CSS背景图像。在我的CSS中,我使用了background-size:cover,并且非常喜欢图像响应不同浏览器宽度的方式。根据图像的宽度,我可以让图像的重要部分始终保持可见和居中,而任一侧的额外宽度仅在宽屏显示器上可见,作为附加效果。将“background-size:cover”应用于Twitter Bootstrap旋转木马幻灯片
我想保留现在使用Bootstrap的Carousel时的相同图像行为,但即使将尺寸指定给幻灯片的视口,仍然无法显示背景图像。我现在已经设置好了,所以每张幻灯片都显示一个单独的CSS类,每个幻灯片都有不同的背景图片,因此可以在三张图片之间滚动。
如果这不可能通过背景图像,它有另一种方式来操纵图像元素,使他们的显示行为是相同的背景大小:盖?
这里是我的HTML:
<div id="myCarousel" class="carousel slide">
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item ad1">
<img src="{{ STATIC_URL }}img/TestBannerAd.png">
</div>
<div class="item ad2">
<img src="{{ STATIC_URL }}img/TestBannerAd2.png">
</div>
<div class="item ad3">
<img src="{{ STATIC_URL }}img/TestBannerAd3.png">
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
我的CSS:
#myCarousel {
width: 100%;
}
.carousel-control {
margin-top: 20px;
}
.carousel-inner {
width: 100%;
height: 400px;
}
.ad1 {
background: url(../img/TestBannerAd.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.ad2 {
background: url(../img/TestBannerAd2.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.ad3 {
background: url(../img/TestBannerAd3.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
但愿这不是一个愚蠢的问题,我们可以算出来!
感谢您发布此信息。我能够实现我想要做的事情,但似乎无法将文本添加到这些幻灯片中。任何想法,我会怎么做你的代码?感谢 – AAA
我已经修改了代码标记为幻灯片标题和文本,里面只与类“旋转木马字幕”有一个标题和段落中的股利。我还添加了“积极”级到第一滑动,就不能正常工作,否则。 –
这就像魅力...谢谢,这是节省很多时间...... –