Colors can be defined using different methods:
-
Color Names: CSS provides predefined color names such as "red", "green", "blue", "yellow", etc. We can simply use the color name as a value for the CSS color property.
-
Hex Codes: Hexadecimal codes are a combination of six letters and numbers that represent the red, green, and blue values of a color. They are preceded by a "#" symbol. For example, "#FF0000" represents the color red.
-
RGB Values: RGB stands for Red, Green, and Blue. It is a color model used to define colors in terms of the intensity of the red, green, and blue light. We can define a color in CSS using RGB values as "rgb(red, green, blue)" where red, green, and blue are integers between 0 and 255.
All of these methods are equally valid and can be used depending on the requirements of the project. Color names are easy to remember and can be used for basic designs, while hex codes and RGB values provide more flexibility and control over the exact color required.
<!DOCTYPE html>
<html>
<head><title>Title</title></head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<body>
<h1 id="name">Same Color</h1>
<h1 id="hex">Same Color</h1>
<h1 id="rgb">Same Color</h1>
</body>
</html>
In this HTML code, the id
attribute is used to uniquely identify three different h1
elements with the values name
, hex
, and rgb
. These identifiers can be used to apply specific styles to each of the h1
elements using CSS.
#name {
background: black;
color:white;
}
#hex {
background: #000000;
color:white;
}
#rgb {
background: rgb(0,0,0);
color:white;
}
The styles defined for each ID specify the background color and text color for that particular element. The three different ways of defining black color are used:
- ID "name": The color is specified by the color name "black".
- ID "hex": The color is specified by a six-digit hexadecimal code "#000000".
- ID "rgb": The color is specified by an RGB color value in the format "rgb(0,0,0)".
In all three cases, the text color is set to white.
No comments:
Post a Comment