1. Use color names<\/strong><\/p>Although there are currently about 184 named colors, they are actually supported by various browsers, and there are only 16 color names recommended as CSS specifications. As shown in the table below. <\/p>
Table 1: Color names recommended by CSS specifications<\/p>
\/*名 稱\t顏 色\t名 稱\t顏 色\t名 稱\t顏 色\nblack\t純黑\tsilver\t淺灰\tnavy\t深藍(lán)\nblue\t淺藍(lán)\tgreen\t深綠\tlime\t淺綠\nteal\t靛青\taqua\t天藍(lán)\tmaroon\t深紅\nred\t大紅\tpurple\t深紫\tfuchsia\t品紅\nolive\t褐黃\tyellow\t明黃\tgray\t深灰\nwhite\t殼白*\/<\/pre>It is not recommended to use color names in web pages, especially large-scale use, to avoid that some color names are not parsed by the browser, or are different Differences in how browsers interpret colors. <\/p>
2. Hexadecimal color<\/strong><\/p>Hexadecimal symbols #RRGGBB and #RGB (such as #ff0000). \"#\" followed by 6 or 3 hexadecimal characters (0-9, A-F). <\/p>
This is the most commonly used color selection method, for example: <\/p>
#f03\n#F03\n#ff0033\n#FF0033<\/pre>3, RGB, red-green-blue (RGB)<\/strong><\/p>The color value is specified as the color of the rgb code. The function format is rgb(R,G,B), and the value can be an integer or percentage from 0-255. <\/p>
rgb(255,0,51)\nrgb(255, 0, 51)\nrgb(100%,0%,20%)\nrgb(100%, 0%, 20%)<\/pre>Extensions: RGBA, Red-Green-Blue-Alpha (RGBa)<\/p>
RGBA extends the RGB color mode to include an alpha channel, allowing the transparency of a color to be set. a represents transparency: 0=transparent; 1=opaque. <\/p>
rgba(255,0,0,0.1) \/* 10% 不透明 *\/ \nrgba(255,0,0,0.4) \/* 40% 不透明 *\/ \nrgba(255,0,0,0.7) \/* 70% 不透明 *\/ \nrgba(255,0,0, 1) \/* 不透明,即紅色 *\/<\/pre>4. HSL, hue-saturation-lightness (Hue-saturation-lightness)<\/strong><\/p>Hue (Hue) represents the color circle (that is, a circle representing a rainbow) ring) at an angle.
Saturation and brightness are expressed as percentages.
100% is full saturation, while 0% is a grayscale.
100% lightness is white, 0% lightness is black, and 50% lightness is \"normal\". <\/p>
hsl(120,100%,25%) \/* 深綠色 *\/ \nhsl(120,100%,50%) \/* 綠色 *\/ \nhsl(120,100%,75%) \/* 淺綠色 *\/<\/pre>Extension: HSLA, Hue-Saturation-Lightness-Alpha (HSLa)<\/p>
HSLa extends from the HSL color mode and includes the alpha channel, which can specify the transparency of a color. a represents transparency: 0=transparent; 1=opaque. <\/p>
hsla(240,100%,50%,0.05) \/* 5% 不透明 *\/ \nhsla(240,100%,50%, 0.4) \/* 40% 不透明 *\/ \nhsla(240,100%,50%, 0.7) \/* 70% 不透明 *\/ \nhsla(240,100%,50%, 1) \/* 完全不透明 *\/<\/pre>5, transparent<\/strong><\/p>Special color value, indicating transparent color. Can be used directly as color. <\/p>
For example: color:transparent Set the font color to transparent<\/p>