HTML Color Codes HTML 颜色代码:

In HTML colors can be added by using style attributes. You can specify a color by its name, its hexadecimal value, or its RGB value. Although novice programmers will probably find it a lot easier to specify colors by their names rather than trying to remember all the different hexadecimal or RGB values; however both hexadecimal and RGB color values provide more color options. 

在HTML中,可以使用样式属性添加颜色。可以通过名称、十六进制值或RGB值指定颜色。虽然新手程序员可能会发现,用名字来指定颜色比记住所有不同的十六进制或RGB值要容易得多;但是,十六进制和RGB颜色值都提供了更多的颜色选项。

Moreover, Hexadecimal and RGB color values provide a choice of over 16 million different colors. Each different value represents a slightly different color; however every computer shows colors differently; therefore the a common set of colors known as web safe colors are used by web designers and programers.

十六进制和RGB颜色值提供了超过1600万种不同颜色的选择。每个不同的值代表一种稍微不同的颜色;然而,每台电脑显示的颜色不同;因此,web设计师和编程人员使用一组称为web安全颜色的通用颜色。

Hexadecimal color codes are made up of a combination of letters and numbers. When using hexadecimal color values are preceded with a hash (#) in your HTML or CSS code.

十六进制颜色码由字母和数字组成。使用十六进制颜色值时,HTML或CSS代码中的值前面会有一个散列(#)。

RGB color codes are made up of 3 values for the red, green and blue channels. RGB values are written as rgb(__,__,__) with each channels value being written inside the parentheses and are separated by commas, which each channel having a value between 0 and 255. An alpha channel can also be added to an RGB color value to add opacity. This is written as rgba(__,__,__,__) with the alpha value being inserted after the blue channel. Values for alpha channels are between 0.0 and 1.0.

RGB颜色代码由红色、绿色和蓝色通道的3个值组成。RGB值被写入 rgb(__,__,__) ,每个通道的值都写入括号内,并用逗号分隔,每个通道的值都在0和255之间。还可以将alpha通道添加到RGB颜色值以添加不透明度。这被写为 rgba(__,__,__) alpha通道的值介于0.0和1.0之间。

The follow Generic Web Safe Colors chart shows 17 basic web safe colors names as specified by the CSS 2.1 specification, along with their corresponding hexadecimal and RGB values.

下面的通用Web安全颜色图表显示了CSS 2.1规范指定的17种基本Web安全颜色名称及其相应的十六进制和RGB值。

Syntax 语法:

Styles are used to add color attributes to various HTML tags. Color styles can be applied to apply color attributes to different block level elements such as a DIV tag <div>, or to different flow content tags such as a paragraph tag <p>, or heading tag <h_>. To add color to an HTML element you use a style attribute which is written as style=“color:_____” with the style attribute being added inside of the opening tag of an HTML element.

样式用于向各种HTML标签添加颜色属性。颜色样式可将将颜色属性应用于不同的块级元素,如DIV标签<div>,或应用于不同的流数据内容标签,如段落标记签<p>,或标题标签<h_>。要向HTML元素添加颜色,需要使用一个样式属性,该属性被写为style=“color:_____”,样式属性被添加到HTML元素的开始标签中。

Several common color style additions include几种常见的颜色样式添加包括:

Change the color of the text 更改文本的颜色: style=“color:_____”

Adding a color boarder 添加颜色边框: style=”border:__px ______ solid;”

Add a HEX background color 添加一个十六进制背景色: style=“background-color:#______”

Add a RGB background color 添加RGB背景色: style=”background-color:rgb(__,__,__)”

Transparent RGB background 透明RGB背景: style=”background-color:rgba(__,__,__,__)”

Example 例:


X11 Colors:

The following X11 colors are supported by all major browsers. These colors have been identified to be appear similar under standard viewing conditions on a variety of real-world monitors even without the use of color management software; therefore these colors are described as having an unambiguous (not open to more than one interpretation) colorimetric definition which is identical on both Mac and PC computer platforms.

所有主要浏览器都支持以下X11颜色。即使不使用颜色管理软件,在各种真实世界的显示器上,这些颜色在标准的观看条件下看起来也很相似;因此,这些颜色被描述为具有在Mac和PC计算机平台上完全相同的明确(不接受多种解释)色度定义。