非常教程

CSS 参考手册教程

CSS color 属性

CSS color 属性

CSS color 属性


实例

不同元素设置text-color:

body { color:red; } h1 { color:#00ff00; } p { color:rgb(0,0,255); }

尝试一下 »

属性定义及使用说明

Color属性指定文本的颜色。

默认值: 未指定
继承:
版本: CSS1
JavaScript 语法: object.style.color="#FF0000"


浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

紧跟在 -webkit-, -ms- 或 -moz- 前的数字为支持该前缀属性的第一个浏览器版本号。

属性
color 1.0 3.0 1.0 1.0 3.5

提示和注释

提示:请使用合理的背景颜色和文本颜色搭配,这样可以提高文本的可读性。


属性值

颜色值可以使用以下几种方式来设置:

描述 实例
颜色的名称 颜色的名称,比如red, blue, brown, lightseagreen等,不区分大小写。
color:red;    /* 红色 */
color:black;  /* 黑色 */
color:gray;   /* 灰色 */
color:white;  /* 白色 */
color:purple; /* 紫色 */
十六进制 十六进制符号 #RRGGBB 和 #RGB(比如 #ff0000)。"#" 后跟 6 位或者 3 位十六进制字符(0-9, A-F)。
#f03
#F03
#ff0033
#FF0033
rgb(255,0,51)
rgb(255, 0, 51)
RGB,红-绿-蓝(red-green-blue (RGB)) 规定颜色值为 rgb 代码的颜色,函数格式为 rgb(R,G,B),取值可以是 0-255 的整数或百分比。
rgb(255,0,51)
rgb(255, 0, 51)
rgb(100%,0%,20%)
rgb(100%, 0%, 20%)
RGBA,红-绿-蓝-阿尔法(RGBa) RGBa 扩展了 RGB 颜色模式,它包含了阿尔法通道,允许设定一个颜色的透明度。a 表示透明度:0=透明;1=不透明。
rgba(255,0,0,0.1)    /* 10% 不透明 */  
rgba(255,0,0,0.4)    /* 40% 不透明 */  
rgba(255,0,0,0.7)    /* 70% 不透明 */  
rgba(255,0,0,  1)    /* 不透明,即红色 */ 
HSL,色相-饱和度-明度(Hue-saturation-lightness) 色相(Hue)表示色环(即代表彩虹的一个圆环)的一个角度。
饱和度和明度由百分数来表示。
100% 是满饱和度,而 0% 是一种灰度。
100% 明度是白色, 0% 明度是黑色,而 50% 明度是"一般的"。
hsl(120,100%,25%)    /* 深绿色 */  
hsl(120,100%,50%)    /* 绿色 */       
hsl(120,100%,75%)    /* 浅绿色 */    
HSLA,色相-饱和度-明度-阿尔法(HSLa) HSLa 扩展自 HSL 颜色模式,包含了阿尔法通道,可以规定一个颜色的透明度。 a 表示透明度:0=透明;1=不透明。
hsla(240,100%,50%,0.05)   /* 5% 不透明 */   
hsla(240,100%,50%, 0.4)   /* 40% 不透明 */  
hsla(240,100%,50%, 0.7)   /* 70% 不透明 */  
hsla(240,100%,50%,   1)   /* 完全不透明 */   

更多实例

实例

颜色为 16 进制值:

body {color: #92a8d1;}

尝试一下 »

实例

颜色值为 RGB:

body {color: rgb(255,0,51);}

尝试一下 »

实例

颜色值为 RGBA:

body {color: rgba(255,0,0,0.7);}

尝试一下 »

实例

颜色值为 HSL:

body {color: hsl(120,100%,25%) ;}

尝试一下 »

实例

颜色值为 HSLA:

body {color: hsla(240,100%,50%, 0.7);}

尝试一下 »


相关文章

CSS 教程: CSS 文本格式

CSS color 属性
CSS 参考手册

CSS 参考手册提供了完整的 CSS 属性列表,每个属性都配有语法说明及实例演示,另外还讲解了 CSS 选择器、颜色值及浏览器支持等相关内容。

CSS 参考手册目录

1.CSS 听觉参考手册
2.CSS 选择器
3.CSS 参考手册
4.CSS3 animation-name 属性
5.CSS3 animation 属性
6.CSS3 @keyframes 规则
7.CSS 浏览器支持
8.CSS 颜色十六进制值
9.CSS 颜色名称
10.CSS 合法颜色值
11.CSS 颜色
12.CSS 单位
13.CSS Web安全字体
14.CSS3 animation-timing-function 属性
15.CSS3 animation-duration 属性
16.CSS background-color 属性
17.CSS background-attachment 属性
18.CSS background 属性
19.CSS3 backface-visibility 属性
20.CSS3 appearance 属性
21.CSS3 animation-play-state 属性
22.CSS3 animation-iteration-count 属性
23.CSS3 animation-delay 属性
24.CSS background-repeat 属性
25.CSS background-position 属性
26.CSS background-image 属性
27.CSS border 属性
28.CSS3 background-size 属性
29.CSS3 background-origin 属性
30.CSS3 background-clip 属性
31.CSS border-bottom-style 属性
32.CSS border-bottom-color 属性
33.CSS border-bottom 属性
34.CSS border-right-style 属性
35.CSS border-right 属性
36.CSS border-left-width 属性
37.CSS border-left-style 属性
38.CSS border-left-color 属性
39.CSS Border-left 属性
40.CSS border-color 属性
41.CSS border-collapse 属性
42.CSS border-bottom-width 属性
43.CSS3 border-bottom-left-radius 属性
44.CSS border-width 属性
45.CSS border-top-color 属性
46.CSS border-top-style 属性
47.CSS border-top-width 属性
48.CSS border-top 属性
49.CSS border-style 属性
50.CSS border-spacing 属性
51.CSS border-right-width 属性
52.CSS border-right-color 属性
53.CSS3 border-image-width 属性
54.CSS3 border-radius 属性
55.CSS3 border-top-left-radius 属性
56.CSS3 border-top-right-radius 属性
57.CSS3 border-image-source 属性
58.CSS3 border-image-slice 属性
59.CSS3 border-image-repeat 属性
60.CSS3 border-image-outset 属性
61.CSS3 border-image 属性
62.CSS3 border-bottom-right-radius 属性
63.CSS3 box-sizing 属性
64.CSS3 box-pack 属性
65.CSS3 box-orient 属性
66.CSS3 box-ordinal-group 属性
67.CSS3 box-lines 属性
68.CSS3 box-flex-group 属性
69.CSS3 box-flex 属性
70.CSS3 box-direction 属性
71.CSS3 box-align 属性
72.CSS bottom 属性
73.CSS3 column-rule-color 属性
74.CSS3 column-rule 属性
75.CSS3 column-gap 属性
76.CSS3 column-fill 属性
77.CSS3 column-count 属性
78.CSS color 属性
79.CSS clip 属性
80.CSS clear 属性
81.CSS caption-side 属性
82.CSS3 box-shadow 属性
83.CSS :after 选择器
84.CSS :before 选择器
85.CSS content 属性
86.CSS3 columns 属性
87.CSS3 column-width 属性
88.CSS3 column-span 属性
89.CSS3 column-rule-width 属性
90.CSS3 column-rule-style 属性
91.CSS font 属性
92.CSS float 属性
93.CSS Empty-cells 属性
94.CSS display 属性
95.CSS direction 属性
96.CSS cursor 属性
97.CSS counter-reset 属性
98.CSS counter-increment 属性
99.CSS3 grid-columns 属性
100.CSS3 font-stretch 属性