There are several ways to use colors in Web pages
1, color name , such as red black white
2, hexadecimal color , commonly used in Web pages, each two-bit represents the value of red-green-blue, such as #ffffff白色 #000000黑色
3, Rgba color , such as RGBA (255,255,255,0.5) Translucent white, this way IE8 and the following incompatible
RGBA (R,g,b,a)
R: Red value. Positive integers | Percentage
G: Green value. Positive integers | Percentage
B: Blue value. Positive integers | Percentage
A:alpha transparency. Value between 0~1.
4, Hsla color value , such as Hsla (360, 50%, 50%,. 5) Translucent red, this way IE8 and the following incompatible
HSLA (H,s,l,a)
H:hue (hue). 0 (or 360) indicates red, 120 is green, 240 is blue, and other values are preferred to specify the color. Value is: 0-360
S:saturation (saturation). Values are: 0%-100%
L:lightness (brightness). Values are: 0%-100%
A:alpha transparency. Value between 0~1.
So how about a random color value?
In general, we can use the RGBA or Hsla mode to random values
1. Random Rgba Color
1) Random one 0~255 value, 2) stitch these values into an RGBA string to
The code is as follows: (Create a random color object with a transparency of 0.8, get the color property of the object and the Rgba color value you want)
// Color Objects function Color () { this. R = Math.floor (Math.random () *255); this. g = Math.floor (Math.random () *255); this. B = Math.floor (Math.random () *255); This This This this. B + ', 0.8) '; }
2. Random Hsla Color
1) Random one 0~360 color value range, 2) assemble Hsla color value string (saturation, brightness, transparency on demand)
// Color Objects function Color () { this. Colorangle = Math.floor (Math.random () *360); This this. Colorangle + ', 100%,50%,1) '; }
How are CSS color values set? And how about a random color?