css中颜色
With CSS you can set the color of an element, background or text. The background color is changed by using the background-color attribute. The color of the element is changed by using the color attribute.
使用CSS可以设置元素 ,背景或文本的颜色 。 通过使用background-color属性可以更改背景色 。 元素的颜色通过使用color属性更改。
Colors in CSS can be specified by the following method,
CSS中的颜色可以通过以下方法指定,
Hexadecimal colors
十六进制颜色
RGB/RGBA colors
RGB / RGBA颜色
HSL/HSLA colors
HSL / HSLA颜色
Predefined color names
预定义的颜色名称
1)十六进制颜色 (1) Hexadecimal colors)
Hex code is used to denote RGB (Red Green Blue) components of a color in base-16 hexadecimal notation. If both values in each of the three RGB pairings (R, G, and B) are the same, then the color code can be shortened into three characters (the first digit of each pairing).
十六进制代码用于以基数16的十六进制表示形式表示颜色的RGB(红绿蓝)分量。 如果三个RGB配对( R,G和B )中的每一个值都相同,则可以将颜色代码缩短为三个字符(每个配对的第一个数字)。
Example:
例:
body {
background-color: #de1205; /* red */
}
2)RGB / RGBA颜色 (2) RGB/RGBA colors)
RGB also is known as RGBa stands for Red, Green, and Blue, and requires three separate values between 0 and 255, put between brackets, that correspond with the decimal color values for respectively red, green and blue.
RGB也称为RGBa,代表红色,绿色和蓝色,并且需要三个介于0和255之间的单独值,放在括号之间,分别对应于红色,绿色和蓝色的十进制颜色值。
RGBa allows you to add an alpha parameter between 0.0 and 1.0 to define opacity.
RGBa允许您在0.0和1.0之间添加一个alpha参数来定义不透明度 。
Example:
例:
div {
background-color: rgb(0, 0, 0); /* black */
color : rgba(255, 0, 0, 0.5); /* red with 0.5 opacity */
}
3)HSL / HSLA颜色 (3) HSL/HSLA Colors)
It is a way to declare a color is to use HSL or HSLa and is similar to RGB and RGBa. HSL stands for hue, saturation, and lightness.
这是一种声明颜色是使用HSL还是HSLa的方法 ,类似于RGB和RGBa 。 HSL代表色相,饱和度和亮度 。
Hue is a degree on the color wheel (from 0 to 360). Saturation is a percentage between 0% and 100%. Lightness is also a percentage between 0% and 100%.
色相是色轮上的度数(从0到360)。 饱和度是介于0%和100%之间的百分比。 亮度也是0%到100%之间的百分比。
HSLa allows you to add an additional alpha parameter between 0.0 and 1.0 to define opacity.
HSLa允许您在0.0到1.0之间添加一个附加的alpha参数来定义不透明度。
Example:
例:
#r1
{
background-color: hsla(120, 90%, 70%, .3); /* green with 30% opacity */
}
4)预定义的颜色 (4) Predefined Colors)
140 color names are predefined in the HTML and CSS color specification.
HTML和CSS颜色规范中预定义了140个颜色名称 。
The Example of some of the colors with hex codes are as follows,
带有十六进制代码的某些颜色的示例如下,
翻译自: https://www.includehelp.com/code-snippets/colors-in-css.aspx
css中颜色