Style Attributes | Color 样式属性 | 颜色:

HTML program codes allow for a large range of very specific colors to be selected and used in a web-design. Usually colors are identified by using either RGB, or HEX values; however, there are some basic colors that can be used by using generic color names. These basic colors include: red, green, blue, cyan, magenta, yellow, black, and white.

HTML程序代码允许在web设计中选择和使用大量非常特定的颜色。通常使用RGB或十六进制值来识别颜色;但是,有一些基本颜色可以通过使用通用颜色名称来使用。这些基本颜色包括:红色、绿色、蓝色、青色、洋红、黄色、黑色和白色。

Note: When writing HTML codes it is important to use the American English spelling for words. For example if you write “color” using the British spelling “colour” you will have an error and the indicated color will not be applied to the HTML element.

注意:在编写HTML代码时,使用美式英语拼写单词很重要。例如,如果使用英国拼写“colour”编写“color”,则会出现错误,并且所指示的颜色将不会应用于HTML元素。

Syntax 语法:

The color attribute is written inside brackets as style-name{color:attribute}.The default color attribute applies to any text inside an HTML element; however color attributes can be applied to other style attributes such as borders or backgrounds.

颜色属性作为样式名{color:attribute}写在括号内;但是,颜色属性可以应用于其他样式属性,例如边框或背景。

An element’s font color can be changed by using the following color statement可以使用以下颜色指令更改元素的字体颜色: 

{color:___}, {color:red; }, {color:blue; }, {color:green; }, etc.

A color attribute can be applied to other style attributes by adding a color code to other style attribute as is shown in the examples below通过向其他样式属性添加颜色代码,可以将颜色属性应用于其他样式属性,如下例所示::

{border:2px solid ____}, {border:2px solid red}, {border:2px solid green}, etc.{background: ____}, {background:red}, {background: green}, etc.

Example 例: