search
HomeWeb Front-endHTML Tutorial第 15 章 CSS 文本样式[下] - 水之原

 学习要点:

1.文本总汇

2.文本样式

3.文本控制

 

主讲教师:李炎恢

 

本章主要探讨 HTML5 中 CSS 文本样式,通过文本样式的设置,更改字体的大小、样式以及文本的方位。

 

一.文本总汇

本节课,我们重点了解一下 CSS 文本样式中文本内容的一些设置方法,样式表如下:

属性名

说明

CSS 版本

text-decoration

装饰文本出现各种划线。

1

text-transform

将英文文本转换大小写。

1

text-shadow

给文本添加阴影

3

text-align

设置文本对齐方式

1,3

white-space

排版中的空白处理方式

1

letter-spacing

设置字母之间的间距

1

word-spacing

设置单词之间的间距

1

line-height

设置行高

1

word-wrap

控制段词

3

text-indent

设置文本首行的缩进

1

 

二.文本样式

CSS 文本样式有三种:文本装饰、英文大小写转换和文本阴影。

1.text-decoration

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    text-decoration</span>:<span style="color: #0000ff;"> underline</span>;
}

解释:设置文本出现下划线。属性值如下表:

说明

none

让本身有划线装饰的文本取消掉

underline

让文本的底部出现一条下划线

overline

让文本的头部出现一条上划线

line-through

让文本的中部出现一条删除划线

blink

让文本进行闪烁,基本不支持了

 

//让本来有下划线的超链接取消 

<span style="color: #800000;">a </span>{<span style="color: #ff0000;">
    text-decoration</span>:<span style="color: #0000ff;"> none</span>;
}

 

2.text-transform

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    text-transform</span>:<span style="color: #0000ff;"> uppercase</span>;
}

解释:设置英文文本转换为大小写。

说明

none

将已被转换大小写的值恢复到默认状态

capitalize

将英文单词首字母大写

uppercase

将英文转换为大写字母

lowercase

将英文转换为小写字母

 

3.text-shadow

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    text-shadow</span>:<span style="color: #0000ff;"> 5px 5px 3px black</span>;
}

解释:给文本添加阴影。其中四个值,第一个值:水平偏移;第二个值:垂直偏移;第三个值:阴影模糊度(可选);第四个值:阴影颜色(可选)。

 

三.文本控制

CSS 文本样式中还有一组对文本进行访问、形态进行控制的样式。

1.text-align

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    text-align</span>:<span style="color: #0000ff;"> center</span>;
}

解释:指定文本的对齐方式。

说明

left

靠左对齐,默认

 right

 靠右对齐

center

居中对齐

 justify

 内容两端对齐

start

让文本处于结束的边界

 end

 让文本处于结束的边界

start 和 end 属于 CSS3 新增的功能,但目前 IE 和 Opera 尚未支持。

 

2.white-space

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    white-space</span>:<span style="color: #0000ff;"> nowrap</span>;
}

解释:处理空白排版方式。

说明

normal

默认值,空白符被压缩,文本自动换行

nowrap

空白符被压缩,文本不换行

pre

空白符被保留,遇到换行符则换行

pre-line

空白符被压缩,文本会在排满或遇换行符换行

pre-wrap

空白符被保留,文本会在排满或遇换行符换行

 

3.letter-spacing

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    letter-spacing</span>:<span style="color: #0000ff;"> 4px</span>;
}

解释:设置文本之间的间距。

说明

normal

设置默认间距

长度值

比如:“数字”+“px”

  

4.word-spacing

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    word-spacing</span>:<span style="color: #0000ff;"> 14px</span>;
}

解释:设置英文单子之间的间距。

说明

normal

设置默认间距

长度值

比如:“数字”+“px”

 

5.line-height

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    line-height</span>:<span style="color: #0000ff;"> 200%</span>;
}

解释:设置段落行高。

说明

normal

设置默认间距

长度值

比如:“数字”+“px”

数值

比如:1,2,3

%

比如:200%

 

6.word-wrap

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    word-wrap</span>:<span style="color: #0000ff;"> break-word</span>;
}

解释:让过长的英文单词断开。

说明

normal

单词不断开

break-word

断开单词

 

7.text-indent

<span style="color: #800000;">p </span>{<span style="color: #ff0000;">
    text-indent</span>:<span style="color: #0000ff;"> 20px</span>;
}

解释:设置文本首行的缩进。

说明

normal

设置默认间距

长度值

比如:“数字”+“px”

 

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
HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use