div { background-color: rgb(255,0,0); opacity: 1; } div { background-color: rgba(255,0,0,1); }
What is the difference between the above two?
The opacity-level describes the transparency-level, where 1 is not transparant at all, 0.5 is 50% see-through, and 0 is completely transparent. Alpha Channel RGBA color values are an extension of RGB color values with an alpha channel - which specifies the opacity of the object.
The primary difference is, the opacity applies to its sub-elements too. In contrast, rgba() applies the transparency of the colour to that particular element only. For example, opacity is set to the div element that contains text and has a border.
The alpha channel contains no color information, only transparency information. The channel is always visualized as a grayscale image.
In digital photography, transparency is the functionality that supports transparent areas in an image or image layer. Certain image formats do not support transparency. Opacity is the extent to which something blocks light.
Opacity sets the opacity value for an element and all of its children; While RGBA sets the opacity value only for a single declaration.
This is well explained here. http://www.css3.info/introduction-opacity-rgba/
Opacity : The opacity property sets the opacity level for an element.(Setting opacity for an elements makes the whole element transparent including its content.)
Defining opacity:
element{opacity:0.5} //makes the element and it's content 50% transparent
The opacity-level describes the transparency-level, where 1 is not transparant at all, 0.5 is 50% see-through, and 0 is completely transparent.
Alpha Channel RGBA color values are an extension of RGB color values with an alpha channel - which specifies the opacity of the object. Background : rgba (Red,Green,Blue,Opacity)
(Setting rgba of an element only makes the element background transparent leaving its content as it is.)
Defining Background rgba: background:
element{ background:rgba(40, 41, 42, 0.5); }
An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).
To convert a hex value of color to rgb: Here
Further Info:
RGBA color values are supported in IE9+, Firefox 3+, Chrome, Safari, and in Opera 10+.
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