我試圖在我的圖像盒類上添加紅色覆蓋圖,但我無法得到結果,因爲: 新的overlay
類替換了舊的圖像,而我只獲取紅色背景。 我需要新的課程,而不是舊的課程。jquery img class overlay
這是我到目前爲止已經試過:
$(function($) {
$(document).on('click', '.wrapper', function(event) {
var target = $(event.target).closest('.wrapper');
\t target.find('.image-box').addClass("overlay");
});
});
.image-box {
height: 300px;
width: 100%;
padding-right: 0px;
padding-left: 0px;
background-position: center;
background-color: #4D4E56;
}
.overlay{
\t background-color:rgba(86, 61, 124, 0.55);
\t transition: 0.5s;
\t filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
height:150px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="image-box"></div>
</div>
嘗試使用background-color:rgba(86,61,124);只有 – Samir
爲類疊加賦予寬度。 – Samir
添加一個類不會創建一個新元素,它使用相同的元素。一個元素只能有一個背景色。可以使用僞元素(:之前或之後)來創建一個具有相同尺寸和不同透明背景色的圖層 – yoavmatchulsky