CSS中的文本格式

CSS文字格式 (CSS text formatting)

CSS text properties allow you to style your text in various ways very easily. Such as color, alignment, spacing, direction, etc.

CSS文本属性使您可以轻松地以各种方式设置文本样式。 例如颜色 , 对齐方式 , 间距 , 方向等。

文字颜色(颜色属性) (Text Color (color property))

The color property is defined by the CSS. We can either write the name of the color or the color code to use our color on the site.

color属性由CSS定义。 我们可以在网站上写下颜色的名称或颜色代码以使用我们的颜色。

Syntax:

句法:

    Element{
        color:white; //#000000
    }

Example:

例:

<!DOCTYPE html>

<head>
    <style>
        h1 {
            color: red;
        }
        
        p {
            color: green;
        }
    </style>
</head>
<html>

<body>
    <p>HELLO WORLD!</p>
    <h1>HEADING</h1>
</body>

</html>

Output

输出量

text formatting in CSS Example Output 1

文本对齐(text-align属性) (Text Alignment (text-align property))

text-align property is used to align text horizontally. The possible values of this property could be: left, right, center, justify and inherit.

text-align属性用于水平对齐文本。 该属性的可能值为: left , right , center , justify和Inherit 。

Syntax:

句法:

    Element{
        text-align:right;
    }

Example:

例:

<!DOCTYPE html>

<head>
    <style>
        h1 {
            Text-align: center;
        }
        
        p {
            Text-align: right
        }
    </style>
</head>
<html>

<body>
    <p>HELLO WORLD!</p>
    <h1>HEADING</h1>
</body>

</html>

Output

输出量

text formatting in CSS Example Output 2

文字修饰(文字装饰属性) (Text Decoration (text-decoration property))

The text-decoration property is used to remove or set decorations from the text. The possible values of this property could be: none, underline, overline, blink, line-through and inherit.

文本装饰属性用于从文本中删除或设置装饰。 该属性的可能值为: none , 下划线 , overline , blink , line-through和Inherit 。

Syntax:

句法:

    Element{
        text-decoration: overline;
    }

Example:

例:

<!DOCTYPE html>

<head>
    <style>
        h1 {
            text-decoration: none;
        }
        
        h2 {
            text-decoration: overline;
        }
    </style>
</head>
<html>

<body>
    <h1>HELLO WORLD!</h1>
    <h2>HEADING</h2>
</body>

</html>

Output

输出量

text formatting in CSS Example Output 3

文本转换(text-transform属性) (Text Transformation (text-transform property))

The text-transform property is used to change the cases of the text for example, it sets the case to lowercase or uppercase or just makes the initial letter capital. Possible values could be: none, capitalize, lowercase, uppercase and inherit.

text-transform属性用于更改文本的大小写,例如,将大小写设置为小写或大写,或者仅使首字母大写。 可能的值可以是: none , 大写 , 小写 , 大写和Inherit 。

Syntax:

句法:

    Element{
        text-transform: none;
    }

Example:

例:

<!DOCTYPE html>

<head>
    <style>
        p {
            text-transform: uppercase;
        }
    </style>
</head>
<html>

<body>
    <p> Some content</p>
</body>

</html>

Output

输出量

text formatting in CSS Example Output 4

文字缩进(text-indent属性) (Text Indentation (text-indent property))

The text-indent property comes in use when we have to indent the first line of text of any element. This property comes with the following values: percentage, length (specifying space) and inherit.

当我们必须缩进任何元素的第一行文本时,将使用text-indent属性。 此属性具有以下值: percent , length (指定空间)和Inherit 。

Syntax:

句法:

    Element{
        text-indent: 50%;
    }

Example:

例:

<!DOCTYPE html>

<head>
    <style>
        p {
            text-indent: 100px;
        }
    </style>
</head>
<html>

<body>
    <p> Some content</p>
</body>

</html>

Output

输出量

text formatting in CSS Example Output 5

字间距(字间距属性) (Word Spacing (word-spacing property))

The word-spacing property deals with the spacing between the words. Possible values are: length, normal and inherit.

单词间距属性处理单词之间的间距。 可能的值为: length , normal和Inherit 。

Syntax:

句法:

    Element{
        word-spacing: 20px;
    }

Example:

例:

<!DOCTYPE html>

<head>
    <style>
        p {
            word-spacing: 50px;
        }
    </style>
</head>
<html>

<body>
    <p> Some content</p>
</body>

</html>

Output

输出量

text formatting in CSS Example Output 6

字母间距(字母间距属性) (Letter Spacing (letter-spacing property))

The letter-spacing is a very useful property when it comes to putting spaces between the letters of the words. This can also have negative values as well. Its values are the same as word-spacing: normal, length and inherit.

当在单词的字母之间放置空格时, 字母间距是非常有用的属性。 这也可以具有负值。 它的值与单词间距相同: normal , length和Inherit 。

Syntax:

句法:

    Element{
        letter-spacing: 10px;
    }

Example:

例:

<!DOCTYPE html>

<head>
    <style>
        h1 {
            letter-spacing: -3px;
        }
    </style>
</head>
<html>

<body>
    <h1>Some content</h1>
</body>

</html>

Output

输出量

text formatting in CSS Example Output 7

线高(线高属性) (Line Height (line-height property))

The line-height or leading property defines the height of a line of a text. Its possible values are length, percentage, inherit, number and normal.

line-height或Leading属性定义文本行的高度。 它的可能值是长度 , 百分比 , 继承 , 数字和正常 。

Syntax:

句法:

    Element{
        line-height:50%;
    }

Example:

例:

<!DOCTYPE html>

<head>
    <style>
        p {
            letter-spacing: 3px;
        }
    </style>
</head>
<html>

<body>
    <h1>Test page</h1>
    <p>
	IncludeHelp site is specially designed to provide help to students, 
	working professionals and job seekers. We are fully dedicated to make each tutorial 
	very simple to learn and understand. This site is not created for business purpose, 
	but for spreading education about programming languages and to help the concerned learners 
	out who are enthusiastic to learn new technologies.
    </p>
</body>

</html>

Output

输出量

text formatting in CSS Example Output 8

翻译自: https://www.includehelp.com/code-snippets/text-formatting-in-css.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值