In CSS, you can set the font color through the color attribute. You only need to set the "color: color value;" style to the element containing the font text. The color attribute is used to specify the color of text; CSS colors can be defined using color names, hexadecimal values, RGB or RGBA values, HSL or HSLA values.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
In CSS, we can set the font color through the color attribute. Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style type="text/css"> body { color: red } h1 { color: #00ff00 } p.ex { color: rgb(0, 0, 255) } </style> </head> <body> <h1 id="这是-nbsp-heading-nbsp">这是 heading 1</h1> <p> 这是一段普通的段落。请注意,该段落的文本是红色的。在 body 选择器中定义了本页面中的默认文本颜色。 </p> <p class="ex">该段落定义了 class="ex"。该段落中的文本是蓝色的。</p> </body> </html>
Rendering
Description: The
color attribute sets the foreground color of an element (in HTML representation , which is the color of the element text); raster images are not affected by color. This color also applies to all borders of the element, unless overridden by border-color or another border-color property.
To set the foreground color of an element, the easiest way is to use the color attribute.
(Learning video sharing: css video tutorial)
How to write css color values:
1. Use color names
Although there are currently about 184 named colors, they are actually supported by various browsers, and there are only 16 color names recommended as CSS specifications. As shown in the table below.
Table 1: Color names recommended by CSS specifications
/*名 称 颜 色 名 称 颜 色 名 称 颜 色 black 纯黑 silver 浅灰 navy 深蓝 blue 浅蓝 green 深绿 lime 浅绿 teal 靛青 aqua 天蓝 maroon 深红 red 大红 purple 深紫 fuchsia 品红 olive 褐黄 yellow 明黄 gray 深灰 white 壳白*/
It is not recommended to use color names in web pages, especially large-scale use, to avoid that some color names are not parsed by the browser, or are different Differences in how browsers interpret colors.
2. Hexadecimal color
Hexadecimal symbols #RRGGBB and #RGB (such as #ff0000). "#" followed by 6 or 3 hexadecimal characters (0-9, A-F).
This is the most commonly used color selection method, for example:
#f03 #F03 #ff0033 #FF0033
3, RGB, red-green-blue (RGB)
The color value is specified as the color of the rgb code. The function format is rgb(R,G,B), and the value can be an integer or percentage from 0-255.
rgb(255,0,51) rgb(255, 0, 51) rgb(100%,0%,20%) rgb(100%, 0%, 20%)
Extensions: RGBA, Red-Green-Blue-Alpha (RGBa)
RGBA extends the RGB color mode to include an alpha channel, allowing the transparency of a color to be set. a represents transparency: 0=transparent; 1=opaque.
rgba(255,0,0,0.1) /* 10% 不透明 */ rgba(255,0,0,0.4) /* 40% 不透明 */ rgba(255,0,0,0.7) /* 70% 不透明 */ rgba(255,0,0, 1) /* 不透明,即红色 */
4. HSL, hue-saturation-lightness (Hue-saturation-lightness)
Hue (Hue) represents the color circle (that is, a circle representing a rainbow) ring) at an angle.
Saturation and brightness are expressed as percentages.
100% is full saturation, while 0% is a grayscale.
100% lightness is white, 0% lightness is black, and 50% lightness is "normal".
hsl(120,100%,25%) /* 深绿色 */ hsl(120,100%,50%) /* 绿色 */ hsl(120,100%,75%) /* 浅绿色 */
Extension: HSLA, Hue-Saturation-Lightness-Alpha (HSLa)
HSLa extends from the HSL color mode and includes the alpha channel, which can specify the transparency of a color. a represents transparency: 0=transparent; 1=opaque.
hsla(240,100%,50%,0.05) /* 5% 不透明 */ hsla(240,100%,50%, 0.4) /* 40% 不透明 */ hsla(240,100%,50%, 0.7) /* 70% 不透明 */ hsla(240,100%,50%, 1) /* 完全不透明 */
5, transparent
Special color value, indicating transparent color. Can be used directly as color.
For example: color:transparent Set the font color to transparent
<style type="text/css"> body{background:hsl(270,100%,50%)} p{ font-size:50px; font-family:"黑体"; /*浏览器私有属性*/ -webkit-text-fill-color:transparent;/*设置文本透明*/ /*使用rgba(0,0,0,0);也可以实现全透明模式*/ -webkit-text-stroke:2px yellow;/*将文本设置透明,再设置个边框后就实现镂空字了*/ /*W3C标准属性*/ /*text-fill-color:transparent;*/ /*text-stroke:2px yellow;*/ } </style> <body> <p>2012年过去了,最忙的是元芳,你怎么看?</p> </body>
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of How to set font color in css. For more information, please follow other related articles on the PHP Chinese website!

在css中,可用list-style-type属性来去掉ul的圆点标记,语法为“ul{list-style-type:none}”;list-style-type属性可设置列表项标记的类型,当值为“none”可不定义标记,也可去除已有标记。

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

在css中,可以利用cursor属性实现鼠标隐藏效果,该属性用于定义鼠标指针放在一个元素边界范围内时所用的光标形状,当属性值设置为none时,就可以实现鼠标隐藏效果,语法为“元素{cursor:none}”。

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。

转换方法:1、给英文元素添加“text-transform: uppercase;”样式,可将所有的英文字母都变成大写;2、给英文元素添加“text-transform:capitalize;”样式,可将英文文本中每个单词的首字母变为大写。

在css3中,可以用“transform-origin”属性设置rotate的旋转中心点,该属性可更改转换元素的位置,第一个参数设置x轴的旋转位置,第二个参数设置y轴旋转位置,语法为“transform-origin:x轴位置 y轴位置”。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
