search
HomeWeb Front-endHTML TutorialCSS: text style (indentation/alignment/character spacing/text decoration/blank space processing)_html/css_WEB-ITnose

Through CSS styles, you can set the indentation, alignment, character spacing and other attributes of the text.

Code compiled from w3school: http://www.w3school.com.cn

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Language" content="zh-cn">  <!--  (1)设置首行缩进:text-indent  (2)水平对齐:text-align   (3)字间隔(设置字,单词 之间的标准间隔):word-spacing  (4)字符间隔(设置字符或字母之间的间隔):letter-spacing  (5)字符转换(大小写):text-transform   (6)文本装饰:text-decoration  (7)处理空白符:white-space  -->  <style>    body {background-color:#e9e9e9}    span.redStyle {color:red}    p#indentStyle {text-indent:5em}    p#indentStyleNega {text-indent:-5em; padding-left: 5em;}    p#indentStylePercent {text-indent:20%}    div.divFixedWidth {width:500px;background-color:#bfb;}    div#outer {width: 500px;background-color:#bfb}    div#inner {text-indent: 10%;}    p#pFixedWidth {width: 200px;}    p.alignLeftStyle{text-align:left}    p.alignRightStyle{text-align:right}    p.alignCenterStyle{text-align:center}    p.bigWordSpace{word-spacing:0.5em}    p.smallWordSpace{word-spacing:-0.2em}    p.bigLetterSpace{letter-spacing:0.2em}    p.smallLetterSpace{letter-spacing:-0.2em}    p.upperCase span {text-transform:uppercase}    p.lowerCase span {text-transform:lowercase}    p.capitalize span {text-transform:capitalize}    p.underlineStyle {text-decoration:underline}    p.overlineStyle {text-decoration:overline}    p.whiteSpaceNormal {white-space:normal}    p.whiteSpacePre {white-space:pre}    p.whiteSpacePreWrap {white-space:pre-wrap}    p.whiteSpacePreLine {white-space:pre-line}    p.whiteSpaceNoWrap {white-space:nowrap}  </style>  <title>CSS 文本</title><!--CSS文本属性可定义文本的外观,可以改变文本的颜色、字符间距,对齐文本,装饰文本,对文本进行缩进等-->  <h3 id="一-首行数字缩进">(一)首行数字缩进</h3>  <p id="indentStyle"><span class="redStyle">首行缩进5em的段落。</span>这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容</p>  <h3 id="二-首行数字缩进为负值">(二)首行数字缩进为负值</h3>  <p id="indentStyleNega"><span class="redStyle">首行缩进-5em,padding-left=5em的段落(悬挂缩进的效果)。</span>这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容</p>  <h3 id="三-首行相对父元素百分比缩进">(三)首行相对父元素百分比缩进</h3>  <div class="divFixedWidth">    <p id="indentStylePercent"><span class="redStyle">首行相对父元素缩进20%。由于父元素是500px,因此本段落首行就缩进100px。</span>这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容这是段落内容</p>  </div>  <hr>  <!--text-indent属性可以继承-->  <div id="outer">    <div id="inner">      some text. some text. some text.      <p id="pFixedWidth">this is a paragragh.</p>    </div>  </div>  <h3 id="四-文本对齐方式">(四)文本对齐方式</h3>  <!--text-align 是一个基本的属性,它会影响一个元素中的文本行互相之间的对齐方式。(将块级元素或表元素居中,要通过在这些元素上适当地设置左、右外边距来实现。)-->  <div class="divFixedWidth">    <p class="alignLeftStyle">这是一个居左的段落</p>    <p class="alignCenterStyle">这是一个居中的段落</p>    <p class="alignRightStyle">这是一个居右的段落</p>  </div>  <hr>  <!--字间隔-->  <h3 id="五-字间隔-设置字-单词-之间的间隔">(五)字间隔:设置字,单词 之间的间隔</h3>  <p>This is a normal paragraph. 这是普通段落,这是普通段落。</p>  <p class="bigWordSpace">The spaces between words will be increased. 单词之间的间距被扩大了,单词之间的间距被扩大了。</p>  <p class="smallWordSpace">The spaces between words will be decreased. 单词之间的间距被缩小了,单词之间的间距被缩小了。</p>  <p>注:word-spacing属性对中文无效。</p>  <hr>  <!--字符间隔-->  <h3 id="六-字符间隔-设置字符或字母之间的间隔">(六)字符间隔:设置字符或字母之间的间隔</h3>  <p>This is a normal paragraph. 这是普通段落,这是普通段落。</p>  <p class="bigLetterSpace">The spaces between letters will be increased. 字符之间的间距被扩大了,字符之间的间距被扩大了。</p>  <p class="smallLetterSpace">The spaces between letters will be decreased. 字符之间的间距被缩小了,字符之间的间距被缩小了。</p>    <hr>  <!--字符转换-->  <h3 id="七-字符转换-改变字母的大小写">(七)字符转换:改变字母的大小写</h3>  <p class="upperCase">Hello world转为大写:<span>Hello world<span></span></span></p>  <p class="lowerCase">Hello world转为大写:<span>Hello world<span></span></span></p>  <p class="capitalize">Hello world转为每个单词首字母大写:<span>Hello world<span></span></span></p>    <hr>  <!--字符装饰-->  <h3 id="八-字符装饰-下划线-贯穿线-等">(八)字符装饰:下划线/贯穿线 等</h3>  <p class="underlineStyle">下划线</p>  <p class="overlineStyle">上划线</p>  <hr>  <!--空格处理-->  <h3 id="九-空格处理">(九)空格处理</h3>  <p class="whiteSpaceNormal">(1)normal:这个    段落里面有 很多 的空格    以及很多的换行符,测试  不同的     空格处理方式</p>  <p class="whiteSpacePre">(2)pre:这个    段落里面有 很多 的空格    以及很多的换行符,测试  不同的     空格处理方式</p>  <p class="whiteSpacePreWrap">(3)pre-wrap:这个    段落里面有 很多 的空格    以及很多的换行符,测试  不同的     空格处理方式</p>  <p class="whiteSpacePreLine">(4)pre-line:这个    段落里面有 很多 的空格    以及很多的换行符,测试  不同的     空格处理方式</p>  <p class="whiteSpaceNoWrap">(5)nowrap:这个    段落里面有 很多 的空格    以及很多的换行符,测试  不同的     空格处理方式</p>
Rendering:




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
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.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

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

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.