css3 rgb,CSS3 Colors

CSS3 Colors

CSS3 Colors

CSS supports color names, hexadecimal and RGB colors.

In addition, CSS3 also

introduces:

RGBA colors

HSL colors

HSLA colors

opacity

Browser Support

The numbers in the table specify the first browser version that fully supports CSS3 color values/property.

Property

RGBA, HSL, and HSLA

4.0

12.0

9.0

3.0

3.1

10.1

opacity

4.0

12.0

9.0

2.0

3.1

10.1

RGBA Colors

RGBA color values are an extension of RGB color values with an alpha channel - which specifies the opacity

for a color.

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).

rgba(255, 0, 0, 0.2);

rgba(255, 0, 0, 0.4);

rgba(255, 0, 0, 0.6);

rgba(255, 0, 0, 0.8);

The following example defines different RGBA colors:

Example

#p1 {background-color: rgba(255, 0, 0, 0.3);}  /* red

with opacity */

#p2 {background-color: rgba(0, 255, 0, 0.3);}  /* green with opacity */

#p3 {background-color: rgba(0, 0, 255, 0.3);}  /* blue

with opacity */

Try it yourself »

HSL Colors

HSL stands for Hue, Saturation and Lightness.

An HSL color value is specified with: hsl(hue, saturation, lightness).

Hue is a degree on the color wheel (from 0 to 360):

0 (or 360) is red

120 is green

240 is blue

Saturation is a percentage value: 100% is the full color.

Lightness is also a percentage; 0% is dark (black) and 100% is white.

hsl(0, 100%, 30%);

hsl(0, 100%, 50%);

hsl(0, 100%, 70%);

hsl(0, 100%, 90%);

The following example defines different HSL colors:

Example

#p1 {background-color: hsl(120, 100%, 50%);}  /* green */

#p2 {background-color: hsl(120, 100%, 75%);}  /* light green */

#p3 {background-color: hsl(120, 100%, 25%);}  /* dark

green */

#p4 {background-color: hsl(120, 60%, 70%);}   /* pastel green */

Try it yourself »

HSLA Colors

HSLA color values are an extension of HSL color values with an alpha channel - which specifies the opacity

for a color.

An HSLA color value is specified with: hsla(hue, saturation, lightness, alpha), where the

alpha parameter defines the opacity. The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

hsla(0, 100%, 30%, 0.3);

hsla(0, 100%, 50%, 0.3);

hsla(0, 100%, 70%, 0.3);

hsla(0, 100%, 90%, 0.3);

The following example defines different HSLA colors:

Example

#p1 {background-color: hsla(120, 100%, 50%, 0.3);}  /* green with opacity */

#p2 {background-color: hsla(120, 100%, 75%, 0.3);}  /* light green with opacity */

#p3 {background-color: hsla(120, 100%, 25%, 0.3);}  /* dark

green with opacity */

#p4 {background-color: hsla(120, 60%, 70%, 0.3);}   /* pastel green

with opacity */

Try it yourself »

Opacity

The CSS3 opacity property sets the opacity for a specified RGB value.

The opacity property value must be a number between 0.0 (fully transparent) and 1.0 (fully opaque).

rgb(255, 0, 0);opacity:0.2;

rgb(255, 0, 0);opacity:0.4;

rgb(255, 0, 0);opacity:0.6;

rgb(255, 0, 0);opacity:0.8;

Notice that the text above will also be opaque.

The following example shows different RGB values with opacity:

Example

#p1 {background-color:rgb(255,0,0);opacity:0.6;}  /* red with opacity

*/

#p2 {background-color:rgb(0,255,0);opacity:0.6;}  /* green with

opacity */

#p3 {background-color:rgb(0,0,255);opacity:0.6;}  /* blue

with opacity */

Try it yourself »

Test Yourself with Exercises!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值