【问题标题】:add background color over owl carousel image在猫头鹰轮播图像上添加背景颜色
【发布时间】:2023-03-20 09:09:01
【问题描述】:

我正在使用jQuery Owl Carousel,我创建了一个图像滑块,我想在其中为滑块图像添加背景颜色。

2019 年的注意事项http://owlgraphic.com 现在重定向到恶意网站。

这是标记:

 <!-- HEADER-02 CONTENT -->
<div class="header-02-sub">

<!-- SLIDER STARTS HERE -->
<div id="owl-slider" class="owl-carousel owl-theme">

          <div class="item">
            <img src="http://placehold.it/1600x700" alt="The Last of us">
            <div class="caption">

             <h1>SOME TITLE HERE</h1>

            </div>               
          </div>
         <div class="item">
            <img src="http://placehold.it/1600x700" alt="The Last of us">
             <div class="caption">

             <h1>SOME TITLE HERE</h1>

            </div>          
          </div>
          <div class="item">
            <img src="http://placehold.it/1600x700" alt="The Last of us">
            <div class="caption">

             <h1>SOME TITLE HERE</h1>

            </div>     
          </div>

        </div>
  <!-- SLIDER ENDS HERE -->      


 </div>

 <!-- END HEADER-02 CONTENT -->

我已经添加了这个 CSS:

.header-02-sub {
background-color:red;
z-index:9999999;
witdth:100%;
height:100%;
}

我也尝试将此代码添加到 #owl-slider 父级或 .item 并且这些都不起作用。

这是一个jsbin

关于如何在幻灯片图像上添加背景颜色的任何建议?

【问题讨论】:

    标签: jquery css twitter-bootstrap owl-carousel


    【解决方案1】:

    .item 元素中添加一个绝对定位的DIV(我们称之为.overlay),然后用

    标记这个新的DIV
    .overlay{
      position: absolute;
      top: 0px;
      left: 0px;
      height: 700px;
      width: 1600px;
      background-color: red;
      opacity: 0.5;
    }
    

    更新:

    如果您的页面是响应式的,请将 position: relative 添加到 .item,然后将 .overlay 的高度和宽度更改为 100%

    .item{
      position: relative;
    }
    .overlay{
      position: absolute;
      top: 0px;
      left: 0px;
      height: 100%;
      width: 100%;
      background-color: red;
      opacity: 0.5;
    }
    

    New JSBin

    【讨论】:

    • 这行得通,但我有一个小问题,图像是响应式的,所以我需要一种方法来让覆盖层覆盖图像而不管屏幕分辨率如何
    • 使用jquery获取图片高宽,分别设置overlay的高宽
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 2015-04-02
    • 2023-04-07
    相关资源
    最近更新 更多