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);
}
Simple solution
if you need to set the gradient to background-image only:
A great way to do it for a simple image is to do it using only CSS to set the background of the HTML element like so.
If you want to get fancy, and set its opacity, then, in IE9+*, you can set a transparent background color of the body. This works by overlaying semitransparent white to make the image whiter, and appear to be brighter. For example, white with 75% opacity (
rgba(255,255,255,.75)
) would produce the following effect.position: relative
, while the body isposition: absolute
. This is to prevent the background color of the body from behaving more like a highlighter of the text in the body.This could even be expanded to something comparable to, but still very distinct from, CSS filters by changing around the body's RGBA color background. For example,
rgba(0,255,0,.75)
would create a very green tint as you can see in the code snippet.rgba(0,255,0,.75)
as something exemplified by{red:0, green:255, blue:0, alpha:'75%'}
.*A full compatibility table can be found at Can I Use. However, please also note that you need to click the "Show All" to see that IE9 supports it.
Addendum
Since I have already answered the question but I have more I want to add, I am titling this section addendum and having it add some potentially helpful information. So, to extrapolate even further on the content above, you could use an SVG as a background image to do wicked awesome things. For example, you could create a loading screen background featuring a cool website icon as you can see in the example of a base64 encoded SVG below.
background-size: cover
CSS causes the SVG logo in the background to be resized to the size of the HTML element.