Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit of using the "transparent" value in the CSS background property before a url of a png?

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!

like image 233
Joel Glovier Avatar asked Dec 16 '09 21:12

Joel Glovier


People also ask

What is transparent property in CSS?

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.

How do I make the background of an image transparent in CSS?

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.

What is background color transparent in CSS?

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.

What is the use of the CSS background image property?

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.


2 Answers

If you're inheriting a background color from another declaration then that should clear it out.

like image 56
Azeem.Butt Avatar answered Oct 04 '22 12:10

Azeem.Butt


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.

like image 28
Paul D. Waite Avatar answered Oct 04 '22 12:10

Paul D. Waite