【问题标题】:How to overlay image on a custom carousel?如何在自定义轮播上叠加图像?
【发布时间】:2019-05-07 22:22:53
【问题描述】:

我有一个来自here 的自定义轮播。 我想在轮播的左上角叠加一张图片。

我已经搜索了所有内容,但我的旋转木马没有任何效果,因为它总是会变形。


    <!-- Carousel -->
    <header>
                <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
                  <ol class="carousel-indicators">
                    <li data-target="#carouselExampleIndicators" data-target="#mycarousel" data-slide-to="0" class="active"></li>
                    <li data-target="#carouselExampleIndicators" data-target="#mycarousel" data-slide-to="1"></li>
                    <li data-target="#carouselExampleIndicators" data-target="#mycarousel" data-slide-to="2"></li>
                  </ol>
                  <div class="carousel-inner" role="listbox">
                    <!-- Slide One - Set the background image for this slide in the line below -->
                    <div class="carousel-item active" style="background-image: url('images/c1.jpg')">
                      <div class="carousel-caption d-none d-md-block">
                        <h2 class="display-4">First Slide</h2>
                        <p class="lead">This is a description for the first slide.</p>
                      </div>
                    </div>
                    <!-- Slide Two - Set the background image for this slide in the line below -->
                    <div class="carousel-item" style="background-image: url('images/c2.jpg')">
                      <div class="carousel-caption d-none d-md-block">
                        <h2 class="display-4">Second Slide</h2>
                        <p class="lead">This is a description for the second slide.</p>
                      </div>
                    </div>
                    <!-- Slide Three - Set the background image for this slide in the line below -->
                    <div class="carousel-item" style="background-image: url('images/c3.jpg')">
                      <div class="carousel-caption d-none d-md-block">
                        <h2 class="display-4">Third Slide</h2>
                        <p class="lead">This is a description for the third slide.</p>
                      </div>
                    </div>
                  </div>
                  <a class="carousel-control-prev" href="#carouselExampleIndicators" 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="#carouselExampleIndicators" role="button" data-slide="next">
                        <span class="carousel-control-next-icon" aria-hidden="true"></span>
                        <span class="sr-only">Next</span>
                      </a>
                </div>
              </header>

    <div class="logo">
                    <img src="images/logo.png">
                </div>


    /* css */
    .carousel-item {
        height: 100vh;
        min-height: 350px;
        background: no-repeat center center scroll;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
      }

    #logo{
        position: absolute;
        top: 0;
        left: 0;
    }

图像只是放在轮播下方,而不是覆盖它。

jfiddle

【问题讨论】:

    标签: html css bootstrap-4 carousel


    【解决方案1】:

    徽标是 HTML 代码中的一个类,在 CSS 中它被选为 ID

    所以,代码将是:

    .logo {
        .....
    }
    

    而不是

    #logo {
        .....
    }
    

    【讨论】:

    • 我从来没有想过这个,因为在我的另一个项目中它工作得很好,但显然轮播改变了这个工作流程。谢谢!
    【解决方案2】:

    没有正确(相对)定位父元素。将代码包装在容器中并相对定位容器,然后包含图像的 div(包装器的子级)将相应地动作。或者,将 div 粘贴在 header 中,这样 logo div 就是 header 的子元素。

    【讨论】:

    • 我只把它放在外面,这样更容易看到它在哪里,而不必在旋转木马内寻找它。由于它无论如何都不起作用,因此不会有什么不同。
    • 问题已经回答了,但还是谢谢你!
    猜你喜欢
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    • 2015-08-01
    • 1970-01-01
    相关资源
    最近更新 更多