Question:
Can I set a transparent background image using a single CSS property? If so, how?
Original Image Issue:
The provided image ("tandem.jpg") is too bright, so you'd like to reduce its opacity to around 0.2 while preserving its use as a background image.
Solution:
While there's no direct CSS property that allows you to set both the background image and opacity simultaneously, you can achieve the desired result using the following technique:
#main { position: relative; } #main:after { content : ""; display: block; position: absolute; top: 0; left: 0; background-image: url(/wp-content/uploads/2010/11/tandem.jpg); width: 100%; height: 100%; opacity : 0.2; z-index: -1; }
Explanation:
This technique effectively creates a transparent layer over the main element, showcasing the background image with the specified opacity.
The above is the detailed content of Can a Single CSS Property Set Both Background Image and Opacity?. For more information, please follow other related articles on the PHP Chinese website!