There are five kinds of values that specify color in CSS — color keywords, system color keywords, hexadecimal color notation, decimal functional rgb notation, and percentage functional rgb notation.
Color Keywords
There are 17 Color Keywords, also called named colors, defined in CSS2.1:
aqua
- rgb(0,255,255)
black
- rgb(0,0,0)
blue
- rgb(0,0,255)
fuchsia
- rgb(255,0,255)
gray
- rgb(128,128,128)
green
- rgb(0,128,0)
lime
- rgb(0,255,0)
maroon
- rgb(128,0,0)
navy
- rgb(0,0,128)
olive
- rgb(128,128,0)
orange
- rgb(255,80,0)
purple
- rgb(128,0,128)
red
- rgb(255,0,0)
silver
- rgb(192,192,192)
teal
- rgb(0,128,128)
white
- rgb(255,255,255)
yellow
- rgb(255,255,0)
Example 1: <p style="font-size:35px;font-family:'Times New
Roman';color:aqua">the quick brown fox jumps over the lazy dog</p>
There are 148 color keywords defined in CSS 3. However, there are only 139
individual colors. This is because there are a pair of color keywords for each of
the gray colors — one spelt "gray" and the other spelt "grey". Also,
fuchsia
and magenta
is the same color, and so is aqua
and cyan
.
Internet Explorer 6 and 7 ignore the following color keywords:
lightgray
, darkgrey
, grey
, dimgrey
,
lightslategrey
, slategrey
, darkslategrey
.
Therefore, the keywords lightgrey
, darkgray
,
gray
, ddimgray
,
lightslategray
,
slategray
, darkslategray
can be used instead because they refer to the same colors
Here is a table of the CSS 3 colors, source(http://en.wikipedia.org/wiki/Web_colors#X11_color_names):
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example 2: <p style="font-size:35px;font-family:'Times New
Roman';color:crimson">the quick brown fox jumps over the lazy dog</p>
System Color Keywords
The system color keywords refer to the colors used by the operating system in its GUI. These keywords make it possible to create a web page with an interface that mimics the viewer's operating system GUI. CSS 2.1 specifies the following system color keywords (source: http://www.w3.org/TR/CSS2/ui.html#system-colors).
ActiveBorder
- Active window border.
ActiveCaption
- Active window caption background color.
AppWorkspace
- Background color of multiple document interface.
Background
- Desktop background color.
ButtonFace
- Face color for three-dimensional display elements.
ButtonHighlight
- Highlight color for three-dimensional display elements (for edges facing away from the light source).
ButtonShadow
- Shadow color for three-dimensional display elements.
ButtonText
- Text on push buttons.
CaptionText
- Text in caption, size box, and scrollbar arrow box.
GrayText
- Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.
Highlight
- Item(s) selected in a control background color.
HighlightText
- Text of item(s) selected in a control.
InactiveBorder
- Inactive window border.
InactiveCaption
- Inactive window caption background color.
InactiveCaptionText
- Color of text in an inactive caption.
InfoBackground
- Background color for tooltip controls.
InfoText
- Text color for tooltip controls.
Menu
- Menu background color.
MenuText
- Text in menus.
Scrollbar
- Scroll bar gray area.
ThreeDDarkShadow
- Dark shadow for three-dimensional display elements.
ThreeDFace
- Face color for three-dimensional display elements.
ThreeDHighlight
- Highlight color for three-dimensional display elements.
ThreeDLightShadow
- Light color for three-dimensional display elements (for edges facing the light source).
ThreeDShadow
- Dark shadow for three-dimensional display elements.
Window
- Window background color.
WindowFrame
- Window frame.
WindowText
- Text in windows.
Example 3: <p style="font-size:35px;font-family:'Times New
Roman';color:WindowText">the quick brown fox jumps over the lazy dog</p>
Hexadecimal Notation
A hexadecimal notation color value consists of the pound sign (#) followed by six or three hexadecimal digits - example: #344da4
. The first two digits (from the left) represent red
, the next two digits represent green
and the last two represent blue
.
Since each two digit pair is in hexadecimal, the maximum value is ff
or 255
in decimal. Thus, each of the three primary colors - red, green, blue are represented by 256 different levels.
For example, #344da4
represents a red
level of 34 hexadecimal or 52 decimal, a green
level of 4d hexadecimal or 77 decimal and a blue
level of a4 hexadecimal or 164 decimal. A level of 255 represents the strongest level of a particular color and a level of 0 represents the weakest level - complete absence of the color.
Numbers can be converted from hexadecimal to decimal and vice versa using a calculator.
Example 4: <p style="font-size:35px;font-family:'Times New
Roman';color:#FF7F50">coral the quick brown fox jumps over the lazy dog</p>
In the above example the color in decimal rgb notation is
rgb(255,127,80)
.
A hexadecimal notation value can be shortened if the value of each primary color consists of a repeated number or letter.
Example 5: <p style="font-size:35px;font-family:'Times New
Roman';color:#AD9"> the quick brown fox jumps over the lazy dog</p>
In the above example, the color value can be expanded to #AADD99
which
is equivalent to rgb(170,221,153)
.
Functional RGB Notation
The Functional RGB Notation consists of a decimal number triplet of either percentages or integers. The triplet represents the three primary colors red
, green
and blue
.
Decimal Functional RGB Notation
In this notation the rgb triplet is specified as three comma separated decimal numbers enclosed in parentheses. The range of values is 0 to 255. Here is an example of the functional rgb notation using a decimal number triplet: rgb(156,45,56)
. In this example the level of red
is 156, green
is 45 and blue
is 56.
Example 6: <p style="font-size:35px;font-family:'Times New
Roman';color:rgb(255,105,180)">the quick brown fox jumps over the lazy dog</p>
Percentage Functional RGB Notation
In this notation the rgb triplet is specified as three comma separated decimal percentages enclosed in parentheses. The range of values is 0% to 100%, decimal values (example 10.5%) are allowed. Any percentage greater than 100% is considered equal to 100%. Example: (350% is considered 100%). The color in the previous decimal functional rgb notation can be converted to percentage function rgb notation using the formula:
(primary color value ÷ 255) × 100
Only one decimal place is necessary since the rounded-off computed value can represent all the numbers from 0 to 255.
Example 7: <p style="font-size:35px;font-family:'Times New
Roman';color:rgb(100%,49.8%,31.3%)">coral the quick brown fox jumps over the
lazy dog</p>
In the above example, the color value can also be expressed as rgb(255,
127,80)
No comments:
Post a Comment