• 密码登录
  • 手机登录
社交账号登录
阅读( ) 收藏( ) 加载中~ 我要纠错

CSS 颜色

使用CSS时,您可以指定不同方式范围内的颜色。

我们可以使用预定义的颜色名称。或者我们可以为每个红色,绿色和蓝色组件使用十进制或十六进制值。

十进制值由逗号分隔,十六进制值为通常以#为前缀,如 #ffffff ,表示白色。

下表具有一些预定义的颜色名称及其十进制和十六进制等效值。

颜色名称十六进制十进制
black#0000000,0,0
green#0080000,128,0
silver#C0C0C0192,192,192
lime#00FF000,255,0
gray#808080128,128,128
olive#808000128,128,0
white#FFFFFF255,255,255
yellow#FFFF00255,255,0
maroon#800000128,0,0
navy#0000800,0,128
red#FF0000255,0,0
blue#0000FF0,0,255
purple#800080128,0,128
teal#0080800,128,128
aqua#00FFFF0,255,255

这些被称为基本颜色名称。

下表显示了可以使用的扩展灰度阴影。

颜色名称十六进制十进制
darkgray#a9a9a9169,169,169
darkslategray#2f4f4f47,79,79
dimgray#696969105,105,105
gray#808080128,128,128
lightgray#d3d3d3211,211,211
lightslategray#778899119,136,153
slategray#708090112,128,144

RGB值简写

对红色,绿色和蓝色分量使用十六进制值。每对都是十六进制符号,范围为00 - FF。

十六进制值通常以#作为前缀,如#ffffff,表示白色。 “纯”蓝色将被写入#0000FF,“纯”红色被写入#FF0000。

#RGB 是上述六位数符号的较短形式。在此格式中,每个数字都被复制以获得等效的六位数值,例如#F7C变为#FF77CC。

颜色函数

颜色名称和简单的十六进制值不是您可以指定颜色的唯一方法。

有许多函数允许您选择颜色。

  • rgb(r,g,b)使用RGB模型指定颜色。
    示例:rgb(112,128,144)
  • rgba(r,g,b,a)使用RGB模型指定颜色,添加了alpha值以指定不透明度。 值为0是完全透明的; 值为1是完全不透明的。
    示例:rgba(112,128,144,0.4)
  • hsl(h,s,l)使用色相,饱和度和亮度(HSL)模型指定颜色。
    示例:hsl(120,100%,22%)
  • hsla(h,s,l,a)使用alpha值来指定不透明度。
    示例:hsla(120,100%,22%,0.4)

rgb(rrr.rr%,ggg.gg%,bbb.bb%)使用0%到100%范围内的RGB值,允许十进制值(例如75.5%)。因此,黑色的值将是rgb(0%,0%,0%),而蓝色将是rgb(0%,0%,100%)。

 rgb(rrr,ggg,bbb)中,接受的值范围是0-255。范围是十六进制的00-FF的十进制等效值。在此格式中,绿色将为rgb(0,255,0),白色将表示为rgb(255,255,255)。

下表列出了颜色名称,十六进制颜色值和rgb颜色值。

颜色HEXCOLORRGB颜色
Black#000000rgb(0,0,0)
Red#FF0000rgb(255,0,0)
Green#00FF00rgb(0,255,0)
Blue#0000FFrgb(0,0,255)
Yellow#FFFF00rgb(255,255,0)
Cyan#00FFFFrgb(0,255,255)
Magenta#FF00FFrgb(255,0,255)
Gray#C0C0C0rgb(192,192,192)
White#FFFFFFrgb(255,255,255)

CSS3中的扩展颜色关键字

颜色名称十六进制RGB

aliceblue#f0f8ff240,248,255

antiquewhite#faebd7250,235,215

aqua#00ffff0,255,255

aquamarine#7fffd4127,255,212

azure#f0ffff240,255,255

beige#f5f5dc245,245,220

bisque#ffe4c4255,228,196

black#0000000,0,0

blanchedalmond#ffebcd255,235,205

blue#0000ff0,0,255

blueviolet#8a2be2138,43,226

brown#a52a2a165,42,42

burlywood#deb887222,184,135

cadetblue#5f9ea095,158,160

chartreuse#7fff00127,255,0

chocolate#d2691e210,105,30

coral#ff7f50255,127,80

cornflowerblue#6495ed100,149,237

cornsilk#fff8dc255,248,220

crimson#dc143c220,20,60

cyan#00ffff0,255,255

darkblue#00008b0,0,139

darkcyan#008b8b0,139,139

darkgoldenrod#b8860b184,134,11

darkgray#a9a9a9169,169,169

darkgreen#0064000,100,0

darkgrey#a9a9a9169,169,169

darkkhaki#bdb76b189,183,107

darkmagenta#8b008b139,0,139

darkolivegreen#556b2f85,107,47

darkorange#ff8c00255,140,0

darkorchid#9932cc153,50,204

darkred#8b0000139,0,0

darksalmon#e9967a233,150,122

darkseagreen#8fbc8f143,188,143

darkslateblue#483d8b72,61,139

darkslategray#2f4f4f47,79,79

darkslategrey#2f4f4f47,79,79

darkturquoise#00ced10,206,209

darkviolet#9400d3148,0,211

deeppink#ff1493255,20,147

deepskyblue#00bfff0,191,255

dimgray#696969105,105,105

dimgrey#696969105,105,105

dodgerblue#1e90ff30,144,255

firebrick#b22222178,34,34

floralwhite#fffaf0255,250,240

forestgreen#228b2234,139,34

fuchsia#ff00ff255,0,255

gainsboro#dcdcdc220,220,220

ghostwhite#f8f8ff248,248,255

gold#ffd700255,215,0

goldenrod#daa520218,165,32

gray#808080128,128,128

green#0080000,128,0

greenyellow#adff2f173,255,47

grey#808080128,128,128

honeydew#f0fff0240,255,240

hotpink#ff69b4255,105,180

indianred#cd5c5c205,92,92

indigo#4b008275,0,130

ivory#fffff0255,255,240

khaki#f0e68c240,230,140

lavender#e6e6fa230,230,250

lavenderblush#fff0f5255,240,245

lawngreen#7cfc00124,252,0

lemonchiffon#fffacd255,250,205

lightblue#add8e6173,216,230

lightcoral#f08080240,128,128

lightcyan#e0ffff224,255,255

lightgoldenrodyellow#fafad2250,250,210

lightgray#d3d3d3211,211,211

lightgreen#90ee90144,238,144

lightgrey#d3d3d3211,211,211

lightpink#ffb6c1255,182,193

lightsalmon#ffa07a255,160,122

lightseagreen#20b2aa32,178,170

lightskyblue#87cefa135,206,250

lightslategray#778899119,136,153

lightslategrey#778899119,136,153

lightsteelblue#b0c4de176,196,222

lightyellow#ffffe0255,255,224

lime#00ff000,255,0

limegreen#32cd3250,205,50

linen#faf0e6250,240,230

magenta#ff00ff255,0,255

maroon#800000128,0,0

mediumaquamarine#66cdaa102,205,170

mediumblue#0000cd0,0,205

mediumorchid#ba55d3186,85,211

mediumpurple#9370db147,112,219

mediumseagreen#3cb37160,179,113

mediumslateblue#7b68ee123,104,238

mediumspringgreen#00fa9a0,250,154

mediumturquoise#48d1cc72,209,204

mediumvioletred#c71585199,21,133

midnightblue#19197025,25,112

mintcream#f5fffa245,255,250

mistyrose#ffe4e1255,228,225

moccasin#ffe4b5255,228,181

navajowhite#ffdead255,222,173

navy#0000800,0,128

oldlace#fdf5e6253,245,230

olive#808000128,128,0

olivedrab#6b8e23107,142,35

orange#ffa500255,165,0

orangered#ff4500255,69,0

orchid#da70d6218,112,214

palegoldenrod#eee8aa238,232,170

palegreen#98fb98152,251,152

paleturquoise#afeeee175,238,238

palevioletred#db7093219,112,147

papayawhip#ffefd5255,239,213

peachpuff#ffdab9255,218,185

peru#cd853f205,133,63

pink#ffc0cb255,192,203

plum#dda0dd221,160,221

powderblue#b0e0e6176,224,230

purple#800080128,0,128

red#ff0000255,0,0

rosybrown#bc8f8f188,143,143

royalblue#4169e165,105,225

saddlebrown#8b4513139,69,19

salmon#fa8072250,128,114

sandybrown#f4a460244,164,96

seagreen#2e8b5746,139,87

seashell#fff5ee255,245,238

sienna#a0522d160,82,45

silver#c0c0c0192,192,192

skyblue#87ceeb135,206,235

slateblue#6a5acd106,90,205

slategray#708090112,128,144

slategrey#708090112,128,144

snow#fffafa255,250,250

springgreen#00ff7f0,255,127

steelblue#4682b470,130,180

tan#d2b48c210,180,140

teal#0080800,128,128

thistle#d8bfd8216,191,216

tomato#ff6347255,99,71

turquoise#40e0d064,224,208

violet#ee82ee238,130,238

wheat#f5deb3245,222,179

white#ffffff255,255,255

whitesmoke#f5f5f5245,245,245

yellow#ffff00255,255,0

yellowgreen#9acd32154,205,50


×