I have often seen stylesheets written where you have something like this:
#anyelement {
background:transparent url(../img/filename.png) no-repeat left top;
}
The value in question is the "transparent" value - what is the benefit of using this value? I have never really used it with my own css files and my PNG images still seem to work fine in all browsers that support PNGs.
Can anybody shed some light on the use of this value??
Thanks!
Image Transparency with the CSS Opacity Property The opacity property takes values from 0.0 to 1.0 , with 1 being the default value for all elements. The lower the value, the more transparent. So if an element is given an opacity of 0 , it would be invisible.
First, we create a <div> element (class="background") with a background image, and a border. Then we create another <div> (class="transbox") inside the first <div>. The <div class="transbox"> have a background color, and a border - the div is transparent.
The CSS color name transparent creates a completely transparent color. Using rgba or hsla color functions, that allow you to add the alpha channel (opacity) to the rgb and hsl functions. Their alpha values range from 0 - 1.
The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element.
If you're inheriting a background color from another declaration then that should clear it out.
Unless I’m missing something, using transparent
in a background
rule doesn’t have any effect.
When you use the background
shorthand property, it always sets values for background-color
, background-image
, background-position
and background-repeat
. Any values you leave out of the rule will be set to their default values, which for background-color
is transparent
anyway.
See http://jsfiddle.net/CN2aJ/2/
Some people might prefer their CSS to be more explicit, and thus include transparent
in there for clarity. But I don’t think it’ll ever affect how the page is displayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With