繁体   English   中英

Bootstrap 覆盖图像无响应

[英]Bootstrap Overlay image not responsive

我正在使用此 CSS 代码在引导程序中的滑块顶部制作图像叠加层,但是在调整图像大小时没有响应:

.overlay {
background: url(../img/bocSlider.png) top left no-repeat;
position: absolute; 
background-position: center;
width: 100%;
height: 100%;
z-index: 10;
pointer-events: none;
  }
     @media (min-width: 768px) and (max-width: 979px) {
      .overlay{

         width:50%;
        height:50%;
  }    
 }

  @media (max-width: 767px) {
     .overlay{

  width:50%;
  height:50%;
  }

  }
@media (max-width: 480px) {
   .overlay{
   width:50%;
  height:50%;

  }
}

下面是我正在使用的滑块的 HTML:

 <div id="myCarousel" class="carousel slide"> <!-- 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> <li data-target="#myCarousel" data-slide-to="3"></li> </ol> <div class="carousel-inner"> <div class="overlay" class="img-responsive"></div> <div class="item active"> <img src="/img/Bar.jpg" class="fill"> </div> <div class="item"> <img src="/img/Outside.jpg" class="fill"> </div> <div class="item"> <img src="/img/Table_1.jpg" class="fill"> </div> <div class="item"> <img src="/img/Tables_2.jpg" class="fill"> </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> </div>

有人可以帮我解决这个问题吗?

图像是 .png

您可以使用背景颜色代替叠加图像。 写就好了

background-color:rgba(0,0,0,.5);

希望这会帮助你。

在你的 css 中添加背景大小属性

.overlay {
background: url(../img/bocSlider.png) top left no-repeat;
position: absolute; 
background-position: center;
background-size: 100%;
width: 100%;
height: 100%;
z-index: 10;
pointer-events: none;
  }

您以错误的方式添加类,并且在引导程序中 img-responsive 适用于 img 标签,

<div class="overlay" class="img-responsive"></div>

应该

<div class="overlay img-responsive"></div>

对于您的代码删除 img-responsive

<div class="overlay"></div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM