【问题标题】:How can I add a cover image that sits on top of my bootstrap carousel?如何添加位于引导轮播顶部的封面图片?
【发布时间】:2015-07-22 19:20:07
【问题描述】:

我有三个图像在整页轮播中旋转。我正在尝试添加一个“封面”图像,可以这么说,它位于三个旋转的顶部。该图像将有一个切口,可让您看到三个在其后面旋转的图像。我只是不确定该图像在 HTML 中的哪个位置或 css 的样子。

<header id="myCarousel" class="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>

    <!-- Wrapper for Slides -->
    <div class="carousel-inner">
        <div class="item active">
            <!-- Set the first background image using inline CSS below. -->
            <div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide One');"></div>
            <div class="carousel-caption">
                <h2>Caption 1</h2>
            </div>
        </div>
        <div class="item">
            <!-- Set the second background image using inline CSS below. -->
            <div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide Two');"></div>
            <div class="carousel-caption">
                <h2>Caption 2</h2>
            </div>
        </div>
        <div class="item">
            <!-- Set the third background image using inline CSS below. -->
            <div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide Three');"></div>
            <div class="carousel-caption">
                <h2>Caption 3</h2>
            </div>
        </div>
    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#myCarousel" data-slide="prev">
        <span class="icon-prev"></span>
    </a>
    <a class="right carousel-control" href="#myCarousel" data-slide="next">
        <span class="icon-next"></span>
    </a>

</header>

<script>
$('.carousel').carousel({
    interval: 500, //changes the speed
    pause: false
})
</script>

html,
body {
    height: 100%;
}

.carousel,
.item,
.active {
    height: 100%;
}

.carousel-inner {
    height: 100%;
}

.fill {
    width: 100%;
    height: 100%;
    background-position: center;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    -o-background-size: cover;
}

【问题讨论】:

  • 你的意思是当轮播图片旋转时,封面图片应该始终显示在轮播上方?!
  • 创建一个可以帮助其他人回答你的小提琴。
  • 这正是我的意思。谢谢

标签: html css twitter-bootstrap carousel


【解决方案1】:

不是 100% 确定我是否理解您的问题。您可以在顶部标签内添加一个 div 并使其绝对定位在顶部。如果需要,调整 z-index 并且不要忘记将标题作为位置:相对。

【讨论】:

  • 所以标题中有一个 div,在 div 里面我的 img 标签和我的图像。您使用什么 z-index # 来确保它始终位于三个旋转的顶部?
  • 尝试类似: 在您的 css 文件中,给这个 beOnTop div 绝对位置、宽度、高度,然后将其放置在您想要的位置。放置一个更高的 z-index 然后应该在后面的元素。确保您可以输入类似 9999999 的内容。
猜你喜欢
  • 2019-12-02
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 2016-10-27
  • 1970-01-01
  • 2015-08-02
  • 2020-07-29
  • 1970-01-01
相关资源
最近更新 更多