So, I can see in CSS references how to set image transparency and how to set a background image. But how can I combine these two in order to set a transparent background image?
I have an image that I'd like to use as a background, but it is too bright - I'd like to turn the opacity down to about 0.2. How can I do this?
#main {
background-image: url(/wp-content/uploads/2010/11/tandem.jpg);
}
I came across this post as I had the same issue then I thought why mess about with css, adjusting values and hitting refresh when you can easily adjust the opacity in Photoshop? Copy the image, paste it as a new layer then move the opacity slider.
Solution with 1 div and NO transparent image:
You can use the multibackground CSS3 feature and put two backgrounds: one with the image, another with a transparent panel over it (cause I think there's no way to set directly the opacity of the background image):
You can't use
rgba(255,255,255,0.5)
because alone it is only accepted on the back, so you I've used generated gradients for each browser for this example (that's why it is so long). But the concept is the following:http://jsfiddle.net/pBVsD/1/
I just added position=absolute,top=0,width=100% in the #main and set the opacity value to the #background
I applied the background to a div before the main.
Since I don't like neither using a png (proably heavier than the jpg) nor an extra element for setting an opacity and considering this would be a presentational enhacement, then I suggest to try JPEGs with Alpha Channels, a technique that uses canvas.
Maybe it could be a nice technique to implement even I don't know if it's appliable in your specific case.
I saw this and in CSS3 you can now place code in like this. Lets say I want it to cover the whole background I would do something like this. Then with
hsla(0,0%,100%,0.70)
or rgba you use a white background with whatever percentage saturation or opacity to get the look you desire.