W3C中文教程
全球最大最新的中文 Web 技术教程
HTML CSS SQL PHP COLORS MYSQL BOOTSTRAP
 

颜色 教程



颜色的显示是由红,绿和蓝三种颜色组合而来的。


Color 名称

在CSS中,颜色可以用颜色名称:

Example

颜色 名称
Red
Orange
Yellow
Cyan
Blue
测试一下 >>

CSS Color 取值

在CSS中, 颜色可以以不同的方式指定:

  • 按照 颜色的名称
  • 按照 RGB 取值
  • 按照 hexadecimal 取值
  • 按照 HSL取值 (CSS3)
  • 按照 HWB 取值 (CSS4)

RGB Colors

RGB color values are supported in all browsers.

An RGB color value is specified with: rgb(red, green, blue).

Each parameter (red, green, and blue) defines the intensity of the color as an integer between 0 and 255.

For example, rgb(0,0,255) is rendered as blue, because the blue parameter is set to its highest value (255) and the others are set to 0.

Example

Color RGB Color
rgb(255,0,0) Red
rgb(0,255,0) Green
rgb(0,0,255) Blue
测试一下 >>

Shades of gray are often defined using equal values for all the 3 light sources:

Example

Color RGB Color
rgb(0,0,0) Black
rgb(128,128,128) Gray
rgb(255,255,255) White
测试一下 >>

Hexadecimal Colors

Hexadecimal color values are also supported in all browsers.

A hexadecimal color is specified with: #RRGGBB.

RR (red), GG (green) and BB (blue) are hexadecimal integers between 00 and FF specifying the intensity of the color.

For example, #0000FF is displayed as blue, because the blue component is set to its highest value (FF) and the others are set to 00.

Example

Color HEX RGB Color
#FF0000 rgb(255,0,0) Red
#00FF00 rgb(0,255,0) Green
#0000FF rgb(0,0,255) Blue
测试一下 >>

Shades of gray are often defined using equal values for all the 3 light sources:

Example

Color HEX RGB Color
#000000 rgb(0,0,0) Black
#808080 rgb(128,128,128) Gray
#FFFFFF rgb(255,255,255) White
测试一下 >>

Upper Case or Lower Case?

You can use upper case or lower case letters to specify hexadecimal values.

Note Lower case are easier to write. Upper case are easier to read.

Color Names

CSS supports 140 standard color names.

In the next chapter you will find a complete alphabetical list of color names with hexadecimal values:

Color Name Hex Color
AliceBlue #F0F8FF
AntiqueWhite #FAEBD7
Aqua #00FFFF
Aquamarine #7FFFD4
Azure #F0FFFF
Beige #F5F5DC
Bisque #FFE4C4