CSS(Cascading Style Sheets)是一种用于描述HTML或XML(包括SVG、MathML等各种XML方言)文档样式的样式表语言。在CSS中,可以通过color
属性来设置文本的颜色。
red
、blue
、green
等。#FF0000
表示红色,其中每两个字符代表红、绿、蓝三种颜色的强度。rgb(255, 0, 0)
表示红色,分别代表红、绿、蓝三种颜色的强度。rgba(255, 0, 0, 0.5)
。hsl(0, 100%, 50%)
表示红色。hsla(0, 100%, 50%, 0.5)
。red
、blue
、green
等。#FF0000
。rgb(255, 0, 0)
。rgba(255, 0, 0, 0.5)
。hsl(0, 100%, 50%)
。hsla(0, 100%, 50%, 0.5)
。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Color Example</title>
<style>
.text-red {
color: red; /* 预定义颜色名 */
}
.text-blue {
color: #0000FF; /* 十六进制颜色代码 */
}
.text-green {
color: rgb(0, 255, 0); /* RGB值 */
}
.text-transparent {
color: rgba(255, 0, 0, 0.5); /* RGBA值 */
}
.text-hsl {
color: hsl(120, 100%, 50%); /* HSL值 */
}
.text-hsla {
color: hsla(120, 100%, 50%, 0.5); /* HSLA值 */
}
</style>
</head>
<body>
<p class="text-red">This text is red.</p>
<p class="text-blue">This text is blue.</p>
<p class="text-green">This text is green.</p>
<p class="text-transparent">This text is transparent red.</p>
<p class="text-hsl">This text is green using HSL.</p>
<p class="text-hsla">This text is transparent green using HSLA.</p>
</body>
</html>
领取专属 10元无门槛券
手把手带您无忧上云