jquery - OwlCarousel slider 中的重叠元素

标签 jquery css owl-carousel


我的 CSS 有问题。
所以我想设置两个带有图像的 Owl Carousel 。我的问题是顶部的图像应该在前景中并且它完全重叠在背景中的图像,但是它有透明元素所以你仍然可以在背景中看到图像。但是因为它与背景图像重叠,您无法使用 Owl Carousel 在背景图像上滑动。我已经用 z-index 尝试了几件事,但它们并没有真正奏效。
我提供了一个简单的代码片段,可以更好地说明我的问题。我想保留有关 z-index 的元素顺序,但您也应该能够使用下方的旋转木马 slider 。任何形式的帮助将不胜感激。
谢谢。

$(document).ready(function(){
	  $(".owl-carousel").owlCarousel({
			loop:true,
			items:1
	  });
	});
.container{
  position:relative;
  background:#eee;
  width:100%;
  height:500px;
}
.top{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  z-index:1;
}
.top .img{
  height:200px;
  background:rgba(100,100,100,0.5);
  text-align:center;
}
.bottom{
	position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
}
.bottom .img{
  height:50px;
  background:white;
  text-align:center;
}
<div class="container">
  <div class="top">
    <div class="owl-carousel">
      <div><div class="img">1</div></div>
      <div><div class="img">2</div></div>
      <div><div class="img">3</div></div>
    </div>
  </div>
  <div class="bottom">
    <div class="owl-carousel">
      <div><div class="img">A</div></div>
      <div><div class="img">B</div></div>
      <div><div class="img">C</div></div>
    </div>
  </div>
</div>

<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.theme.default.min.css" rel="stylesheet"/>
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/owl.carousel.js"></script>

最佳答案

z-index 仅适用于 position 属性已明确设置为 absolute 、 fixed 或 relative 的元素。由于您已经设置好所有内容,您只需将 z-index:2 添加到 .bottom

$(document).ready(function(){
	  $(".owl-carousel").owlCarousel({
			loop:true,
			items:1
	  });
	});
.container{
  position:relative;
  background:#eee;
  width:100%;
  height:500px;
}
.top{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  z-index:1;
}
.top .img{
  height:200px;
  background:rgba(100,100,100,0.5);
  text-align:center;
}
.bottom{
	position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  z-index:2;
}
.bottom .img{
  height:50px;
  background:white;
  text-align:center;
}
<div class="container">
  <div class="top">
    <div class="owl-carousel">
      <div><div class="img">1</div></div>
      <div><div class="img">2</div></div>
      <div><div class="img">3</div></div>
    </div>
  </div>
  <div class="bottom">
    <div class="owl-carousel">
      <div><div class="img">A</div></div>
      <div><div class="img">B</div></div>
      <div><div class="img">C</div></div>
    </div>
  </div>
</div>

<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.theme.default.min.css" rel="stylesheet"/>
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/owl.carousel.js"></script>

关于jquery - OwlCarousel slider 中的重叠元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47331940/

相关文章:

javascript - Owl Carousel JS返回第一张图片

jquery - 将 jquery 插件从字数统计更改为字符插件?

未找到 Jquery 方法

jquery - GWT 项目不解释 Bootstrap 的 HTML 标记的工具提示部分

jQuery UI Datepicker - 日期范围 - 突出显示之间的日期

html - 如何同时修改很多html文件?

javascript - 无法更改 Material UI Select 组件的填充

css - 是否可以使用 css3 选择所有元素,即使它们具有特殊样式

javascript - Owl Carousel ,到达第一个/最后一个元素后禁用导航

javascript - Owl Carousel 返回错误