Home  >  Article  >  Web Front-end  >  How to change text color with css

How to change text color with css

王林
王林Original
2021-05-14 16:37:4210835browse

The way to change the text color in css is to set the color attribute, such as [color:red;] or [color:#00ff00;], which means setting the text to red.

How to change text color with css

The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.

It is actually very simple to change the color of text in CSS. You only need to add the Color attribute, which can specify the color of the text.

We can set the color in the following ways.

Color name: Color name, such as red, blue, brown, lightseagreen, etc., is not case-sensitive.

HEX: Hexadecimal symbols #RRGGBB and #RGB (e.g. #ff0000). "#" followed by 6 or 3 hexadecimal characters (0-9, A-F).

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 0 -255 as an integer or percentage.

For example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<style>
body {color:red;}
h1 {color:#00ff00;}
p.ex {color:rgb(0,0,255);}
</style>
</head>

<body>
<h1>这是标题 1</h1>
<p>这是一个普通的段落。请注意,本文是红色的。页面中定义默认的文本颜色选择器。</p>
<p class="ex">这是一个类为"ex"的段落。这个文本是蓝色的。</p>
</body>
</html>

Let’s take a look at the running effect:

How to change text color with css

Related learning video sharing: css video tutorial

The above is the detailed content of How to change text color with css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn