Page 50 - CSS
P. 50
Color names
CSS
div {
background-color: red; /* red */
}
HTML
<div>This will have a red background</div>
• The example used above is one of several ways that CSS has to represent a single color.
Hex color codes
Hex code is used to denote RGB components of a color in base-16 hexadecimal notation. #ff0000,
for example, is bright red, where the red component of the color is 256 bits (ff) and the
corresponding green and blue portions of the color is 0 (00).
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). #ff0000 can be shortened to
#f00, and #ffffff can be shortened to #fff.
Hex notation is case-insensitive.
body {
background-color: #de1205; /* red */
}
.main {
background-color: #00f; /* blue */
}
RGB / RGBa
Another way to declare a color is to use RGB or RGBa.
RGB stands for Red, Green and Blue, and requires of three separate values between 0 and 255,
put between brackets, that correspond with the decimal color values for respectively red, green
and blue.
RGBa allows you to add an additional alpha parameter between 0.0 and 1.0 to define opacity.
header {
background-color: rgb(0, 0, 0); /* black */
}
https://riptutorial.com/ 28

