In CSS, setting font color is a basic style attribute. It is implemented through the color attribute. In this article, we will learn how to set the font color using the color property.
color attribute
The color attribute is a property used to set color in CSS. It can be used to set colors for text, background, borders, and other elements.
The color attribute can use predefined color names, such as red, green, etc., or you can use hexadecimal or RGB values to specify colors.
Here are some examples of using the color attribute to set font color:
h1 {
color: red;
}
p {
color : #0000ff;
}
span {
color: rgb(255, 0, 0);
}
In the above code, we used Red, blue and RGB red to set the colors of different elements.
Predefined color names
In CSS, there are some predefined color names that can be used directly. Here are some commonly used color names and their corresponding colors:
Of course, the above is just a part of them. In addition to these, there are many other color names that can be used.
Hexadecimal Color Code
In addition to the predefined color names, we can also use hexadecimal color codes to specify colors. The hexadecimal color code consists of 6 characters, of which the first two characters represent red, the middle two characters represent green, and the last two characters represent blue. Each character can be a number between 0-9 or a letter between A-F. Here are some examples:
RGB color value
RGB color value defines the color by specifying the numerical values of the three colors of red, green, and blue. The range of each value is 0-255. Here are some examples:
rgb(255, 0, 0): red
rgb(0, 255, 0): green
rgb(0, 0, 255): blue
rgb(128, 128, 128): Gray
Set transparency
We can also set the transparency of the font through the color attribute. Transparency is specified using the opacity attribute, and the value range is 0-1, where 0 is completely transparent and 1 is completely opaque. Here is an example:
p {
color: rgba(0, 0, 255, 0.5);
}
In the above code, we used rgba( ) to set color and transparency. Among them, r, g, and b represent the values of the three colors of red, green, and blue respectively, and a represents the transparency. In this example we set the color to blue and the transparency to 0.5, which is 50% transparency.
Conclusion
Through the above explanation, we can see that in CSS, setting font color is a very convenient style attribute. We only need to specify the required color to change the font color of the element. At the same time, we can also control the transparency of the font by setting the transparency to enhance the visual effect of the page.
The above is the detailed content of set font color css. For more information, please follow other related articles on the PHP Chinese website!