css - 让背景图像显示在 Bootstrap 轮播的第一张幻灯片上

标签 css twitter-bootstrap

我创建了一个 Bootstrap 轮播,我正在使用自定义 CSS 为三张幻灯片中的每一张定义背景图像。由于某种原因,背景图像没有出现在第一张幻灯片上,尽管幻灯片 2 和 3 的背景图像显示正常。我不知道哪里出了问题。我认为这可能与仅应用于第一张幻灯片的事件类有关?这是第一张幻灯片的 HTML 和 CSS,轮播称为 myCarousel,谢谢:

HTML:

<!-- class item means item in carousel -->        
    <div id="slide1" class="item active">


        <!--
        <img src="http://placehold.it/1200x500">
         -->

        <h1>HELLO THERE</h1>

        <div class="carousel-caption">

            <h4>High Quality Domain Names</h4>
            <p>Domains that can help your business marketing</p>

        </div> <!-- close carousel-caption -->

        </div> <!-- close slide1 -->

CSS:

#myCarousel .item { height: 400px; } 


      <!-- top left is the background position of the image, no repeat          because we don't want the background image repeating -->
         #slide1 {
        background: url('images/carousel_medium_01.jpg') top center no-        repeat;
  }

最佳答案

而不是将代码直接放在 <div class="item"> 上我建议制作一个嵌套的 div(替换图像)并应用 height , widthbackground-image那里的属性。像这样:

HTML

<div class="carousel-inner" role="listbox">
    <div class="item">
        <div class="item-custom first"></div>
    </div>
    <div class="item">
        <div class="item-custom second"></div>
    </div>
    <div class="item active">
        <div class="item-custom third"></div>
    </div>
</div>

CSS

.item-custom {
    height: 100%;
    width: 100%;
}

然后为您的 .first , .second , 和 .third您可以添加 background-images 的类你要。那应该让你朝着正确的方向前进。希望对您有所帮助。

关于css - 让背景图像显示在 Bootstrap 轮播的第一张幻灯片上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37842414/

相关文章:

html - 如何将图像中的div居中? (使用 flex 但不使用背景图像)

html - 具有相同高度的 div 和 span

javascript - JS脚本需要时间来改变背景颜色

javascript - Bootstrap carousel 滑动时滑动高度变化bug

html - 包含 Bootstrap CSS 时背景图像未出现在 div 上

twitter-bootstrap - Bootstrap 3 : bootstrap-select and input-group-addon

CSS 按钮 - 仅在文本上链接,而不在按钮上链接

html - 如何在 Bootstrap 中不重叠地 float div

html - 如何使容器在列内居中?

jquery - 可扩展的 Bootstrap 页脚