[英]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.