我有一些DIV,有一些改變div背景圖片的不透明度
文字和背景圖片。我想減少背景圖像的不透明度。但是,當我將不透明度應用於DIV時,會影響DIV中的文本。如何在不更改DIV中文本的不透明度的情況下更改背景圖片的不透明度?我有這個代碼,我從另一個問題在stackoverflow,我用它來減少另一個div的不透明度,但我不知道如何修改它來實現上述問題。
function convertHex(hex,opacity){
hex = hex.replace('#','');
r = parseInt(hex.substring(0,2), 16);
g = parseInt(hex.substring(2,4), 16);
b = parseInt(hex.substring(4,6), 16);
result = 'rgba('+r+','+g+','+b+','+opacity/100+')';
return result;
}
$(".add_to_cart_button").click(function() {
$(".cart-contents").css("background-color",convertHex('#f47d32',40));
});
此主題在這裏覆蓋:http://stackoverflow.com/questions/4183948/css-set-background-image-with-opacity –
是圖片動態還是靜態?如果是靜態的,可以在Photoshop或類似軟件中減少不透明度,然後將其另存爲.PNG。 請注意,這只是其中一個選項。 – harisdev
也相關:[設置背景圖像的不透明度而不影響子元素](http://stackoverflow.com/questions/4997493/set-opacity-of-background-image-without-affecting-child-elements) – showdev