Home Web Front-end HTML Tutorial 第 15 章 CSS 文本样式[下] - 水之原

第 15 章 CSS 文本样式[下] - 水之原

May 20, 2016 pm 04:49 PM

 学习要点:

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>;
}
Copy after login

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

说明

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>;
}
Copy after login

 

2.text-transform

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

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

说明

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>;
}
Copy after login

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

 

三.文本控制

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

1.text-align

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

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

说明

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>;
}
Copy after login

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

说明

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>;
}
Copy after login

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

说明

normal

设置默认间距

长度值

比如:“数字”+“px”

  

4.word-spacing

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

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

说明

normal

设置默认间距

长度值

比如:“数字”+“px”

 

5.line-height

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

解释:设置段落行高。

说明

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>;
}
Copy after login

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

说明

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>;
}
Copy after login

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

说明

normal

设置默认间距

长度值

比如:“数字”+“px”

 

Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

How to efficiently add stroke effects to PNG images on web pages? How to efficiently add stroke effects to PNG images on web pages? Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

See all articles