css - Owl Carousel 元素内容 z-index

标签 css z-index owl-carousel

我在设置 owl carousel item 内容的 z-index 时遇到问题。

每个轮播元素都有背景图片和文本内容。

固定覆盖应该在元素(背景图像)上,但不在元素内容上。

固定覆盖不能成为轮播元素的一部分,它必须在幻灯片变化时保持静止。

我有什么: enter image description here

我想要什么: enter image description here

我尝试了所有不同的方法,包括各种 z-index 值以及所有元素的不同定位,但都没有成功。

HTML、PHP:

<div class="intro">

    <div class="owl-carousel owl-theme">
    <?php
    foreach ($Services as $key => $service) {
        echo '<div class="item ' . $key .'" style="background: url(' . $css_path . $service->img_mainpage . '">';
            echo '<div class="hdr_main"><a href="/' . slug($service->title) . '">' . $service->title . '</a></div>';
            echo '<span class="about">' . $service->about . '</span>';
        echo '</div>';
    }
    ?>
    </div>

    <div class="fixed-overlay">
        <?php include(__DIR__ . '/../../assets/gui/mainpage-polygon.svg'); ?>  
    </div>

</div>

CSS:

div.intro {
    position: relative;
    height: 100vh;
    background: rgb(0, 121, 201);
}

div.intro .fixed-overlay {
    position: absolute;
    top: 0px;
    left: 0px;
    height: 100vh;
    width: 60%;
    z-index: 3;
}

.owl-carousel {
    height: 100vh;
    z-index: 2;
}

.owl-carousel .item {
    height: 100vh;
    display: flex;
    justify-content: center;
    flex-direction: column;
    text-align: right;
    padding-right: 13%;
    background-repeat: no-repeat !important;
    background-size: cover !important;
    background-position: center center !important;
}

.item .hdr_main a {
    z-index: 9999;
}

谢谢。

最佳答案

.item {
    z-index: 1;
}

.owl-carousel {
    z-index: -1;
}

试试这个

关于css - Owl Carousel 元素内容 z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44278473/

相关文章:

javascript - 如何让 jQuery 只选择第一个 closest() 元素?

javascript - Owl Carousel 2 无法在调整窗口大小上工作

css - OwlCarousel 左右卡片导航 :react js

javascript - 具有大 DOM 的移动设备上的 CSS translate3d 性能问题

php - Wordpress:在表中搜索元素

css - 仅将 css 应用于 div 的第一个未知元素

javascript - 如果在 jQuery 中选择了选项,则显示 div

javascript - 将 z-index 分配给 Javascript 插件

html - 视差布局和 z-index

css - 将 Bootstrap Dropdown 置于最前面