PHP前端开发

详解CSS 文本属性(Text)

百变鹏仔 4周前 (09-20) #CSS
文章标签 详解

css text(文本)属性用于定义文本的外观,比如文本的颜色,对齐文本,装饰文本,文本颜色,行间距等。本篇文章带大家了解一下css 文本属性(text),希望对大家有所帮助!

CSS 文本属性(Text)


用于属性名CSS 版本浏览器支持继承性默认值
① 颜色的前景色 (文本/文本装饰/边框/当前颜色的 颜色) 。color1都支持。IE 所有版本 不支持属性值“inherit”。yesnot specified
② 文本的书写方向。文本/表列/水平溢出的 方向 (文本方向 可用标签的 dir 属性 替代)。direction2同上。yesltr
③ 标点字符 是否位于线框之外。属性: 悬挂标点的 位置和符号 (实验中 属性)。hanging-punctuation3safari 10.1+支持,其他 都不支持yesnone
④ 字符间距 (字符之间的 额外空白/空间)。letter-spacing1同上。yesnormal
行高。设置 行高/行间距 (一行多高,影响 行之间的 距离) 。line-height1同上。yesnormal
⑤ 标点字符 修剪。punctuation-trim3都不支持yesnone
⑥ 文本 水平对齐 方式。text-align1都支持。IE 所有版本yes如果 direction 属性是 ltr,则默认值是 left;如果 direction 是 rtl,则为 right。 不支持属性值“inherit”。
⑦ 文本最后一行 水平对齐方式 (搭配 direction,text-align 属性)。text-align-last3IE11+,edge14+部分支持,FF52+ chrome49+ opera45+支持,safari不支持。yesauto
⑧ 文本 装饰(线)。text-decoration1同上,且IE、Chrome 或 Safari 不支持 “blink” 属性值。nonone.(块元素 首行) 文本的 缩进量 (空白长度)。
⑨ 添加 文本强调符号(形状,颜色,位置) 。text-emphasis3IE,Edge 不支持,FF52+ safari10.1+ 支持,chrome49+部分支持。nonone
⑩ 文本两端对齐的 空间分隔方式 (搭配text-align属性)。text-justify3IE11+,edge14+部分支持,FF55+支持,其他不支持。yesauto
⑪ 文本的阴影 (影响 装饰线 text-decoration)。text-shadow2都支持。IE 10及以上才支持。yesnone
文本 大小写转换。text-transform1都支持。IE 所有版本 不支持属性值“inherit”。yesnone
⑫ 文本的轮廓。text-outline3都不支持yesnone
⑬ 隐藏文本溢出时 的显示 (搭配 overflow,white-space,display 属性)。text-overflow3都支持,不需要前缀。noclip
⑭ 文本添加阴影。text-shadow3都支持,IE10+支持yesnone
⑮ 文本的换行规则。text-wrap3都不支持yesnormal
⑯ 双向文本的 重写/覆盖 (搭配 direction属性)。unicode-bidi2
yes
⑰ 空白和换行的 处理。white-space1都支持。IE 所有版本 不支持属性值“inherit”。yesnormal
⑱ 单词 换行/断行 位置 (能否 词内断行)。word-break3都支持。IE6+支持。yesnormal
⑲ 对长的不可分割的单词 进行分割并换行到下一行。单词 断行时的 断行位置 (断句/断行 方式)。word-wrap3都支持,IE6+yesnormal
⑳ 单词/字 之间的 距离。word-spacing1同上yesnormal

1. color 属性: 颜色的前景色 (文本/文本装饰/边框/当前颜色的 颜色)

  • 元素的 前景色:
  • 颜色color属性设置了 一个 元素的前景色


  • 前景色    
  • 背景色就是 纸张的颜色,前景色就是 画笔画出的颜色

  • /* 关键字值 Keyword values */color: currentcolor;/* 颜色名称 <named-color> values */color: red;color: orange;color: tan;color: rebeccapurple;/* 十六进制颜色 <hex-color> values */color: #090;color: #009900;color: #090a;color: #009900aa;/* <rgb> values ,逗号 可以换成空格,但是目前 最好别这么做,兼容性还没那么好*/color: rgb(34, 12, 64);/*rgb()中带不透明度值,浏览器支持度不好,用rgba()*/color: rgb(34, 12, 64, 0.6);color: rgba(34, 12, 64, 0.6);color: rgb(34 12 64 / 0.6);color: rgba(34 12 64 / 0.3);color: rgb(34.0 12 64 / 60%);color: rgba(34.6 12 64 / 30%);/* <hsl> values ,逗号 可以换成空格,但是目前 最好别这么做,兼容性还没那么好*/color: hsl(30, 100%, 50%);/*hsl()中带 不透明度值,浏览器支持度不好,用 hsla()*/color: hsl(30, 100%, 50%, 0.6);color: hsla(30, 100%, 50%, 0.6);color: hsl(30 100% 50% / 0.6);color: hsla(30 100% 50% / 0.6);color: hsl(30.0 100% 50% / 60%);color: hsla(30.2 100% 50% / 60%);/* Global values */color: inherit;color: initial;color: unset;</hsl></rgb></hex-color></named-color>

  • 十六进制: hex_number      
  • rgb 代码: rgb(),rgba()      
  • hsl 代码: hsl(),hsla()      
  • 继承: inherit      
  • 注意: 值必须是 统一的颜色color。
  • 它 不能是 一个渐变色的值,渐变色 实际上是一种 图像了,而不是一种颜色.。

  • 文本颜色 默认继承性  


  • 立即学习“前端免费学习笔记(深入)”;


    color {    width: 600px;    border: 10px dashed;    padding: 10px;    /*把一段文字 设置成红色的 方法*/    color: red;    color: #f00;    color: #ff0000;    color: rgb(255,0,0);    color: rgb(100%,0%,0%);    color: hsl(0,100%,50%);    /*设置 半透明的红色 = 不透明值 等于一半的 红色*/    color: #ff000080;    color: rgba(255,0,0,0.5);    color: hsla(0,100%,50%,0.5);}
    红色半透明的红色

    2. direction 属性: 文本/表列/水平溢出的 方向 (文本方向 可用标签的 dir 属性 替代)

  • 嵌入方向: 由 unicode-bidi 属性 创建的 嵌入方向。
  • 文本/块元素 默认对齐: 设置 文本/块级元素 的默认对齐方式
  • 单元格 流动方向: 单元格(表列) 在表行中 流动的方向。

  • /* 关键字值 Keyword values */direction: ltr;direction: rtl;/* 全局通用的属性值 Global values */direction: inherit;direction: initial;direction: unset;

  • 从右到左: rtl    
  • 继承父亲: inherit    

  • 单元格 不从表列 继承direction属性:
  • 搭配使用:
  • 不受 all 属性影响:


  • .color {    width: 450px;    border: 10px dashed;    padding: 10px;        /*设置文本的方向*/    direction: rtl;}
    默认的文本方向: ltr 从左到右设置成 从右到左 direction: rtl;
  • direction: rtl; =

    : 两个效果 是一样的,dir: direction 的简写.

  • .dirTest {    border: 1px solid;    width: 300px;    direction: rtl;    background-color: #d0d0d0;}.dirTest td, th {    border: 1px solid;}
        	
                                                                                                                                                                                   
    ①姓名②爱吃的水果名③爱好
                     小明                              葡萄                 乒乓球
                     莉莉                              苹果             动漫
    默认方向: 从左到右设置 从右到左

    3. CSS3 hanging-punctuation 属性: 悬挂标点的 位置和符号 (实验中 属性)

  • 实验中属性:

  • /* 关键字值 Keyword values */hanging-punctuation: none;hanging-punctuation: first;hanging-punctuation: last;hanging-punctuation: force-end;hanging-punctuation: allow-end;/* 两个值 Two keywords */hanging-punctuation: first force-end;hanging-punctuation: first allow-end;hanging-punctuation: first last;hanging-punctuation: last force-end;hanging-punctuation: last allow-end;/* 三个值 Three keywords */hanging-punctuation: first force-end last;hanging-punctuation: first allow-end last;/* 全局值 Global values */hanging-punctuation: inherit;hanging-punctuation: initial;hanging-punctuation: unset;

  • 首行开始 行框外: first    
  • 末行结尾 行框外: last    
  • 对齐不合适 挂起: allow-end    
  • 行尾的 句号逗号 挂起: force-end    

  • 3 个值: 使用下列其中一项:


  • 4. letter-spacing 属性 : 字符间距 (字符之间的 额外空白/空间)



    /* 关键字值 Keyword value */letter-spacing: normal;/* 长度值 <length> values */letter-spacing: 0.3em;letter-spacing: 3px;letter-spacing: .3px;/* 全局值 Global values */letter-spacing: inherit;letter-spacing: initial;letter-spacing: unset;</length>

  • 指定 字符额外间距: length    
  • 继承父亲: inherit    


  • 对于具有 非常大的 负值的文本
  • 根据字体 调整 字符间距:

  •  


        	<p>    	    业精于勤是一个汉语成语,拼音是 yè jīng yú qín,意思是指 学业的精进 在于勤奋。出处唐·韩愈《进学解》:“业精于勤,荒于嬉;行成于思,毁于随。    	</p>
    .textTest {    width: 450px;    border: 10px dashed;    padding: 10px;    /*字符之间的间距*/    letter-spacing: normal;}
    正常间距 (默认值) normal增加 0.2em的额外间距 letter-spacing: 0.2em;
    减少 0.2em的额外间距 letter-spacing: -0.2em;字符间距 不正常的字体(太大/太小) 2em, -0.9em

    5. line-height 属性: 设置 行高/行间距 (一行多高,影响 行之间的 距离)

  • ❷ 对于 非替换的 内联元素
  • 影响 行间距: 会影响 文本行与行 之间的 距离


  • /* 关键字值 Keyword value */line-height: normal;/* 无单位值: 字体大小 font-size的倍数  Unitless values: use this number multipliedby the element's font size */line-height: 3.5;/* 长度值 <length> values */line-height: 3em;/* 百分比值 <percentage> values */line-height: 34%;/* 全局值 Global values */line-height: inherit;line-height: initial;line-height: unset;</percentage></length>

  • 一个数字(无单位),字体大小的 倍数: number(等同于 百分比值的简写)

  • 优点: 当元素内的 子元素的文本 字体大小font-size 不同时,能设置 相对于 子元素的 当前字体大小的行高.
  • 长度值: length

  • 字体大小的 百分比值:%

  • 继承父亲: inherit

  • 不能负值: 行高 不允许 负值,负值会被视作 无效值.

  • 默认行高/行间距:




  • 确保行高 按比例缩放:


  • .textTest {    width: 450px;    border: 10px dashed;    padding: 10px;    font-size: 16px;    line-height: 1.5em;}
    默认 文本行高 = normal 值绝对长度值 行高 line-height: 40px;
    相对长度值 行高 1.5em = 150%不带单位 纯数字 line-height: 1.5;

  • html  
  •     	<div>    		<h1>业精于勤是一个汉语成语,拼音是 yè jīng yú qín,意思是指 学业的精进 在于勤奋。出处唐·韩愈《进学解》:“业精于勤,荒于嬉;行成于思,毁于随。</h1>    	    <p>业精于勤是一个汉语成语,拼音是 yè jīng yú qín,意思是指 学业的精进 在于勤奋。出处唐·韩愈《进学解》:“业精于勤,荒于嬉;行成于思,毁于随。</p>    	</div>
    .textTest {    width: 450px;    border: 10px dashed;    padding: 10px;    font-size: 16px;}
    默认 文本行高 = normal 值设置成 绝对长度值时: 25px (h1 的文本 行高太挤)
    设置成 相对长度值: 1.5em = 150%设置成 纯数字 不带单位: line-height: 1.5;
  • 不带单位的 纯数字  

  • 6. CSS3 punctuation-trim 属性: 标点修剪 (浏览器 都不支持)



  • ② 修剪 开启标志符号: start    
  • ③ 修剪闭合标点符号: end
  • ④ allow-end
  • ⑤ adjacent

  • 7. text-align 属性: 文本 水平对齐 方式

  • 通过指定 行框 与哪个点对齐



  • /* 关键字值 Keyword values */text-align: left;text-align: right;text-align: center;text-align: justify;/*下方的属性值 支持度还不好 暂时不用少用*/text-align: justify-all;text-align: start;text-align: end;text-align: match-parent;/* 表列中 基于字符的对齐 Character-based alignment in a table column */text-align: ".";text-align: "." center;/* 块对齐值 Block alignment values (非标准语法 Non-standard syntax) */text-align: -moz-center;text-align: -webkit-center;/* 全局值 Global values */text-align: inherit;text-align: initial;text-align: unset;

  • 右对齐: right    
  • 设置文本流向 从右到左 direction:rlt时 的默认值.
  • 居中对齐: center    
  • 两端对齐: justify    
  • 继承父亲: inherit    
  • 默认值    

  • ② 设置 文本水平对齐后

    • 文本水平对齐 text-align的 浏览器支持


    示例1: 设置一段文本的 水平对齐方式

    .textTest {    width: 400px;    border: 10px dashed;    padding: 10px;    font-size: 16px;    margin: 10px;}
    左对齐 text-align:left;右对齐 text-align:right;
    居中对齐 text-align:center;两端对齐 text-align:justify;

    margin: 0 auto;

    7.1 CSS3 text-align-last 属性: 文本最后一行 水平对齐方式 (搭配 direction,text-align 属性)


    /* 关键字值 Keyword values */vertical-align: baseline;vertical-align: sub;vertical-align: super;vertical-align: text-top;vertical-align: text-bottom;vertical-align: middle;vertical-align: top;vertical-align: bottom;/* 长度值 <length> values */vertical-align: 10em;vertical-align: 4px;/* 百分比值 <percentage> values */vertical-align: 20%;/* 全局值 Global values */vertical-align: inherit;vertical-align: initial;vertical-align: unset;</percentage></length>

  • 与 direction 关联,参考起点: start    
  • 右对齐:
  • 浏览器 默认方向: 如果没有设置 direction,则按照 浏览器文本的 默认显示方向 来确定。
  • 与 direction 关联,参考终点: end    
  • 左对齐: left    
  • 右对齐: right    
  • 居中对齐: center    
  • 两端对齐: justify    



  • .textTest {    width: 400px;    border: 10px dashed;    padding: 10px;    margin: 0 auto;    font-size: 16px;    /*文本水平对齐*/    text-align: left;    /*文本最后一行 水平对齐*/    text-align-last: auto;}
    ① 默认显示② text-align-last: auto;
    ③ 起点对齐 text-align-last: start;④ 终点对齐 text-align-last: end;
    ⑤ 左对齐 text-align-last: left;⑥ 右对齐 text-align-last: right;
    ⑦ 居中对齐 text-align-last: center;⑧ 两端对齐 text-align-last: justify;

    7.2 CSS3 text-justify 属性: 文本两端对齐的 空间分隔方式 (搭配 text-align 属性)


    text-justify: none;text-justify: auto;text-justify: inter-word;text-justify: inter-character;text-justify: distribute; /* 已废弃的属性值 Deprecated value */

  • 禁用 两端对齐: none    
  • 调整 单词间距离: inter-word    
  • 调整 字符间距离: inter-character    
  • 分散: distribute (已废弃 属性值)


  • .textjustify{    width: 30%;    background-color: #d0d0d0;    padding: 10px;	    border: solid black 2px;    font-size: 1.2em;	    /*text-align: justify;*/    /*text-justify:auto;*/    /*text-justify:none;*/    /*text-justify:inter-word;*/    /*text-justify:inter-character;*/    /*text-justify:distribute;*/}
        <p>金无足赤,人无完人。出自宋·戴复古《寄兴》:“黄金无足色,白璧有微瑕。求人不求备,妾愿老君家。” 也比喻不能要求一个人没有一点缺点错误,应该严以律己,宽以待人。<br>No one is perfect, everyone will make mistakes,be strict with yourself and lenient toward others.</p>
    默认 水平对齐水平 两端对齐 text-align: justify; ( 默认= text-justify:auto;)
    禁用 两端对齐 text-justify:none;调整 单词间距离 inter-word
    调整 字符间距离 inter-character分散 distribute (已废弃属性值)


    7.3 vertical-align 属性: 垂直对齐方式 (针对 行内元素,表格单元格内容)

  • ③ 块级元素的垂直对齐: 不使用 vertical-align.

  • display =
  • ❸ inline-table
  • 行内/(内联)元素: 基本上是 包装文本的 标签。
  • 它可以用来 把图片 垂直放置在 一行文本中
  • 表格单元格: 垂直对齐 表格的单元格内容

  • /* Keyword values */vertical-align: baseline;vertical-align: sub;vertical-align: super;vertical-align: text-top;vertical-align: text-bottom;vertical-align: middle;vertical-align: top;vertical-align: bottom;/* <length> values */vertical-align: 10em;vertical-align: 4px;/* <percentage> values */vertical-align: 20%;/* Global values */vertical-align: inherit;vertical-align: initial;vertical-align: unset;</percentage></length>

  • 父元素的 下标基线: sub      
  • 父元素的 上标基线: super      
  • 父元素 文本顶部: text-top      
  • 父元素 文本底部: text-bottom      
  • 父元素的 中线: middle      

  • 父元素基线 (位移的 行高的 指定百分比值): %      
  • 使 元素的基线 对齐到 父元素的基线之上的 给定百分比
  • 负值: 默认向上位移, 负值表示 方向相反, 向下位移.
  • 相对行的 值

  • 整行的底部: bottom      
  • 属性值 的正负

  • Ⅱ. 针对 表格 单元格内容 的值  
  • 行的顶部 对齐: top    
  • 行的居中 对齐: middle    
  • 行的底部 对齐: bottom    
  • 可以负值: 可以是负数。

  • 基线: (baseline)是
  • super  
  • adj. 标在上方的
  • n. 上标


  • .verticalTest{width: 700px;text-decoration: underline overline;font-size: 1.5em;/*line-height = font-size x 1.5 = 1.5em x 1.5 = 1.5 x 16 x 1.5*/line-height: 1.5em;background-color: #d0d0d0;padding: 10px;border: 2px solid green;}.verticalTest img{ /* 10px/16px = 0.625 */margin-right: 0.625em;}
        <p>        baseline:        @@##@@        sub:        @@##@@        super:        @@##@@        text-top:        @@##@@        text-bottom:        @@##@@        middle:        @@##@@    </p>    <p>        0px:(基线重叠)= baseline        @@##@@        10px (父元素 基线上方10px)        @@##@@        0.5em:        @@##@@        -0.5em:        @@##@@5        0%:        @@##@@        -50%:        @@##@@    </p>    <p>    	top:        @@##@@    	bottom:         @@##@@           </p>

    .verticalTable{width: 50%;}table.verticalTable ,.verticalTable th,.verticalTable td{border: 1px solid green;}.verticalTable td{padding: 10px;background-color: #d0d0d0;}
        <!-- 表格单元格内容的 垂直对齐 -->    
                                                                              
    基线对齐行的顶部居中行的底部一段文字(未设置垂直对齐)
    baselinetopmiddlebottom自知之明, 是一个汉语成语,读音为 zì zhī zhī míng,指了解自己的情况,能正确认识自己的 长处与短处。 出自《老子》。

    8. text-decoration 属性: 文本 装饰(线)

  • 后代元素会继承 装饰线: 如果后代元素 没有自己的装饰,祖先元素上 设置的装饰会 “延伸”到 后代元素中。

  • 简写属性: text-decoration属性是一种 简写属性,并且可以使用 普通属性三个值中的任何一个。

  • text-decoration-color      
  • text-decoration-style      

  •  ||  || 
  • 下划线: underline    
  • 上划线: overline    
  • 贯穿线(删除线): line-through    
  • 闪烁: blink    
  • 继承父亲: inherit    
  • 做简写属性时: text-decoration 可以同时设置 装饰线的位置,样式 和 颜色.


  • .textdec {/*给文本 添加下划线*/    text-decoration: underline;    width: 30%;    background-color: #d0d0d0;    padding: 10px;    line-height: 1.5em;}.textdec strong {/*取消强调文本的下划线*/    text-decoration: none;    color: green;}
        <p>        <strong>少壮不努力,老大徒伤悲。</strong>意思是,年轻力壮的时候 不奋发图强,到了老年 再悲伤也没用了。出处,《乐府诗集·长歌行》    </p>
  • 两个 装饰线:
  • 可以在子元素中 再添加一次 装饰线,会变成子元素的颜色.

  • .decline{    background-color: #d0d0d0;    text-decoration:underline wavy #008000;/*	text-decoration-line: underline;text-decoration-style:wavy;text-decoration-color: green;*/}
        <p>    	<del>纸上得来终觉浅,</del>绝知此事要躬行。    </p>

    8.1 text-decoration-line: 文本 装饰线的位置 (上 中 下)


    /* 单个 关键字值 Single keyword */text-decoration-line: none;text-decoration-line: underline;text-decoration-line: overline;text-decoration-line: line-through;text-decoration-line: blink;/* 多个 关键字值,同时指定几条装饰线 Multiple keywords */text-decoration-line: underline overline;               /* Two decoration lines */text-decoration-line: overline underline line-through;  /* Multiple decoration lines *//* 全局值  Global values */text-decoration-line: inherit;text-decoration-line: initial;text-decoration-line: unset;

  • 下划线: underline    
  • 上划线: overline    
  • 删除线(贯穿线): line-through    
  • 文本闪烁: blink(已弃用的 属性值)



  • .decline{    background-color: #d0d0d0;text-decoration-line: overline;/*text-decoration-line: line-through;*//*text-decoration-line: underline;*//*text-decoration-line: blink;*/}
        <p>    	纸上得来终觉浅,绝知此事要躬行。    </p>
    上划线 overline删除线(贯穿线) line-through
    下划线 underline闪烁 (无任何效果,blink 属性值浏览器不支持)

    8.2 text-decoration-style: 文本 装饰线的 样式

  • 语义化的标签:
  • 简写属性: 当要设置 装饰线的 修饰属性时,用 text-decoration 简写属性 会比分别写多个属性 更方便。

  • /* 关键字值 Keyword values */text-decoration-style: solid;text-decoration-style: double;text-decoration-style: dotted;text-decoration-style: dashed;text-decoration-style: wavy;/* 全局值 Global values */text-decoration-style: inherit;text-decoration-style: initial;text-decoration-style: unset;

  • 双实线: double    
  • 点虚线:dotted    
  • 虚线: dashed    
  • 波浪线: wavy, 美 /ˈweɪvi/
  • 不画线: -moz-none(尚未标准化)


  • .decline{    background-color: #d0d0d0;text-decoration-line: underline;text-decoration-style:double;/*text-decoration-style:dotted;*//*text-decoration-style:dashed;*//*text-decoration-style:wavy;*/}
    双实线 double点虚线 dotted
    直虚线 dashed波浪线 wavy

    8.3 text-decoration-color: 文本 装饰线的 颜色

  • 设置 不同装饰线 不同颜色的方法    


  • .decline{    background-color: #d0d0d0;text-decoration-line: underline;text-decoration-style:wavy;text-decoration-color: green;}.decline del{text-decoration-line: line-through;text-decoration-color:red;}
        <p>    	<del>纸上得来终觉浅,</del>绝知此事要躬行。    </p>

    9. CSS3 text-emphasis 属性: 添加 文本强调符号




    /* 初始值 Initial value */text-emphasis: none; /* No emphasis marks *//* 字符串值 <string> value */text-emphasis: 'x';text-emphasis: '点';text-emphasis: '\25B2';text-emphasis: '*' #555;text-emphasis: 'foo'; /* 不应使用。它可以仅被计算为“f” 或呈现为“f” Should NOT use. It may be computed to or rendered as 'f' only *//* 关键字值 Keywords value */text-emphasis: filled;text-emphasis: open;text-emphasis: filled sesame;text-emphasis: open sesame;/* 关键词值 与 颜色 相结合 Keywords value combined with a color */text-emphasis: filled sesame #555;/* 全局值 Global values */text-emphasis: inherit;text-emphasis: initial;text-emphasis: unset;</string>

  • Ⅰ. 空心实心    
  • 空心的: open      
  • Ⅱ. 强调符号的形状    
  • 大点/大圆圈: circle      
  • 实心/空心 双圆圈: double-circle      
  • 实心/空心 三角形: triangle      
  • 芝麻符号: sesame      
  • 这是在 没有其他形状的情况下,垂直书写模式的 默认形状.
  • 指定 字符串:      
  • Ⅲ. 颜色:    



  • .textemphasis{    width: 35%;    /*background-color: #d0d0d0;*/    padding: 10px;	    border: solid black 2px;    font-size: 1.2em;}.textemphasis strong{-webkit-text-emphasis-position:under;-webkit-text-emphasis:dot;-webkit-text-emphasis:open dot;/*-webkit-text-emphasis:circle;*//*-webkit-text-emphasis:open circle;*//*-webkit-text-emphasis:double-circle;*//*-webkit-text-emphasis:open double-circle;*//*-webkit-text-emphasis:triangle;*//*-webkit-text-emphasis:open triangle;*//*-webkit-text-emphasis:sesame;*//*-webkit-text-emphasis:open sesame;*//*指定字符串 作为文本强调的符号*//*-webkit-text-emphasis:"z";*//*-webkit-text-emphasis:"x";*//*-webkit-text-emphasis:"大";*/    /*同时设置 空心/实心/强调符号/颜色*//*-webkit-text-emphasis: circle open;*//*-webkit-text-emphasis: circle open red;*/}
            <p>        	<strong>取其精华,去其糟粕。</strong>是一个汉语成语,读音qǔ qí jīng huá qù qí zāo pò意思是吸取事物中最好的东西,舍弃事物中坏的,无用的东西。        </p>
    小点: dot = filled dot小圆圈: open dot
    大点: circle大圆圈: open circle
    实心 双圆圈: double-circle空心 双圆圈: open double-circle
    实心 三角形: triangle空心 三角形: open triangle
    实心 芝麻符: sesame空心 芝麻符: open sesame
    指定为 英文字符: "z"指定为 汉字: "大"
    默认 颜色/位置:circle指定 颜色/位置: circle open red
  • 默认: 实心的.

  • 指定字符 不能指定空心/实心:

  • 视觉效果的 区别: 文本小的时候,有些 相同 文本强调符号 区别看起来不明显.


  • 9.1 text-emphasis-style 属性: 文本强调符号的 样式/形状


    /* 初始值 Initial value */text-emphasis-style: none; /* 没有强调符号 No emphasis marks *//*  值 value */text-emphasis-style: 'x';text-emphasis-style: '点';text-emphasis-style: '\25B2';text-emphasis-style: '*';text-emphasis-style: 'foo'; /* 不应使用。它可以仅被计算为“f”或呈现为“f” Should NOT use. It may be computed to or rendered as 'f' only *//* 关键字值 Keywords value */text-emphasis-style: filled;text-emphasis-style: open;text-emphasis-style: filled sesame;text-emphasis-style: open sesame;/* 全局值  Global values */text-emphasis-style: inherit;text-emphasis-style: initial;text-emphasis-style: unset;

  • 空心的: open      
  • Ⅱ. 强调符号的形状    
  • 大点/大圆圈: circle      
  • 实心/空心 双圆圈: double-circle      
  • 实心/空心 三角形: triangle      
  • 芝麻符号: sesame      
  • 这是在 没有其他形状的情况下,垂直书写模式的 默认形状.
  • 指定 字符串:      


  • 9.2 text-emphasis-color 属性: 文本强调符号的 颜色


    /* 初始值 Initial value */text-emphasis-color: currentColor;/* 合法颜色值 <color> */text-emphasis-color: #555;text-emphasis-color: blue;text-emphasis-color: rgba(90, 200, 160, 0.8);text-emphasis-color: transparent;/* 全局值 Global values */text-emphasis-color: inherit;text-emphasis-color: initial;text-emphasis-color: unset;</color>


    9.3 text-emphasis-position: 文本强调符号的 位置


    /* 初始值 Initial value */text-emphasis-position: over right;/* 关键字值 Keywords value */text-emphasis-position: over left;text-emphasis-position: under right;text-emphasis-position: under left;text-emphasis-position: left over;text-emphasis-position: right under;text-emphasis-position: left under;/* 全局值 Global values */text-emphasis-position: inherit;text-emphasis-position: initial;text-emphasis-position: unset;

  • 下方: under    
  • 右边: right    
  • 左边: left    

  • 几种语言的 文本强调符号的 偏向位置.
  • 语言文本强调符号的首选位置
    水平 书写模式垂直 书写模式
    ① 日语上方 over右边 right
    ② 韩语
    ③ 蒙古语
    ④ 汉语下方 under右边 right


    10. text-indent 属性: (块元素 首行) 文本的 缩进量 (空白长度)


    /* 长度值 <length> values */text-indent: 3mm;text-indent: 40px;/* 百分比值 相对于 包含自身的元素的 宽度 <percentage> value   relative to the containing block width */text-indent: 15%;/* 关键字值 目前尚未标准化 不要使用 Keyword values */text-indent: 5em each-line;text-indent: 5em hanging;text-indent: 5em hanging each-line;/* 全局值 Global values */text-indent: inherit;text-indent: initial;text-indent: unset;</percentage></length>

  • 允许使用 负值。
  • 默认值:0。
  • 父元素宽度 百分比值: %    
  • 继承父亲: inherit    
  • ④ 缩进每一行: each-line(实验中属性,尚未标准化)
  • ⑤ 反转缩进(类似 悬挂效果): hanging(实验中属性,尚未标准化)



  • .textindent {    width: 40%;    background-color: #d0d0d0;    padding: 10px;    /*设置文本缩进*/    text-indent: 50px;/*  text-indent: 3em;    text-indent: -2em;    text-indent: 10%;*/    }
        <p>    	“<strong>勿以恶小而为之,勿以善小而不为。</strong>惟贤惟德,能服于人。” 劝人要进德修业,有所作为。不要因为好事小 而不做,更不能因为坏事小 而去做。小善积多了,就成为利天下的大善,而小恶积多了则 “足以乱国家”。    </p>
    绝对值缩进 50px相对值缩进 3em
    负值缩进 (悬挂缩进) -2em百分比缩进 10%

    11. CSS3 text-outline 属性: 文本轮廓 (浏览器 都不支持)

  • ② 模糊半径。
  • ③ 颜色。

  • 12. CSS3 text-overflow 属性: 隐藏文本溢出时 的显示 (搭配 overflow,white-space,display 属性)



    overflow: hidden;white-space: nowrap;

    /* 行尾的 溢出行为  Overflow behavior at line end   Right end if ltr, left end if rtl */text-overflow: clip;text-overflow: ellipsis;text-overflow: "…";text-overflow: fade;text-overflow: fade(10px);text-overflow: fade(5%);/* 溢出 在左端|在右端的行为 ,方向性 没有影响 Overflow behavior at left end | at right end   Directionality has no influence */text-overflow: clip ellipsis;text-overflow: "…" "…";text-overflow: fade clip;text-overflow: fade(10px) fade(10px);text-overflow: fade(5%) fade(5%);/* 全局值 Global values */text-overflow: inherit;text-overflow: initial;text-overflow: unset;

  • 省略号: ellipsis    
  • 指定 字符串: string    
  • 裁剪处 显示空白: 如果想在 裁剪处 显示空白符,可以使用 ('').

  • 2 个值: 给定两个值
  • 每个值 被指定为:

  • ② text-overflow    

  • width: 100%;  /*也可以是固定值、min-width这些*/white-space: nowrap;  /*强制文本不能换行*/overflow: hidden;  /*隐藏溢出内容*/text-overflow: ellipsis;

  • 倒数四个 都是实验中属性,支持度也很差


  • .textjoverflow{    width: 30%;    background-color: #d0d0d0;    padding: 10px;	    border: solid black 2px;    font-size: 1.2em;	    /*设置不换行,才会有文本溢出*/    white-space: nowrap;    /*设置 overflow 溢出隐藏,文本溢出显示 才有效*/    overflow: hidden;    text-overflow: clip;    /*text-overflow: ellipsis;*/    /*目前不支持 指定字符串 所以此值无效*/    /*text-overflow: "";*/    /*direction: rtl;*/}
        <p>金无足赤,人无完人。“黄金无足色,白璧有微瑕。求人不求备,妾愿老君家。” <br>No one is perfect, everyone will make mistakes.</p>
    默认显示不允许换行时的 默认溢出显示
    溢出文本 被隐藏 overflow: hidden;隐藏的溢出文本 被裁剪 (默认值) text-overflow: clip;
    隐藏的溢出文本 = 省略号 text-overflow: ellipsis;文本流向 从右向左 direction: rtl; (行尾溢出)

    13. text-transform 属性: 文本 大小写转换


  • 在德语中
  • 在荷兰语中
  • 在希腊语中
  • 在爱尔兰语中

  • /* 关键字值 Keyword values */text-transform: none;text-transform: capitalize;text-transform: uppercase;text-transform: lowercase;text-transform: full-width;text-transform: full-size-kana;/* 全局值 Global values */text-transform: inherit;text-transform: initial;text-transform: unset;

  • 字符 保持不变(它们保留 元素文本中 写入的原始大小写)。
  • 首字母大写: capitalize      
  • 全大写: uppercase      
  • 全小写: lowercase      
  • 继承父亲: inherit      

  • CSS 并没有规定 哪一种是正确的,所以这两种 都是可以的。

  • .texttransform{    width: 35%;    background-color: #d0d0d0;    padding: 10px;    font-weight: bold;	    font-size: 1.2em;	    /*改变文本的大小写*/    /*text-transform:capitalize;*/    /*text-transform:uppercase;*/    /*text-transform:lowercase;*/}
        <p>金无足赤,人无完人。<br>No one is perfect, everyone will make mistakes.</p>
    默认样式首字母大写 capitalize
    全大写 uppercase全小写 lowercase

    14. CSS3 text-shadow 属性: 文本的阴影 (含 装饰线 text-decoration)


    /* x 偏移量 offset-x | y 偏移量 offset-y | 模糊半径 blur-radius | 颜色 color */text-shadow: 1px 1px 2px black; /* color | offset-x | offset-y | blur-radius */text-shadow: #fc0 1px 0 10px; /* offset-x | offset-y | color */text-shadow: 5px 5px #558abb;/* color | offset-x | offset-y */text-shadow: white 2px 5px;/* offset-x | offset-y/* 使用默认的 颜色和模糊半径 */text-shadow: 5px 10px;/* 全局值 Global values */text-shadow: inherit;text-shadow: initial;text-shadow: unset;

  • 水平阴影 偏移量(必需): h-shadow

  • 垂直阴影 偏移量( 必需): v-shadow

  • 模糊距离: blur

  • 阴影颜色: color


  • 每个阴影的 属性值    
  • ② 如果有第三个 长度值 参数

  • 文本阴影 适用的伪元素:



  • .textshadow{    width: 40%;    background-color: #d0d0d0;    padding: 10px;    font-weight: bold;	    font-size: 1.5em;    text-shadow:3px 3px green ;}
        <p>海纳百川,有容乃大;壁立千仞,无欲则刚。</p>
    设置 水平和垂直阴影 text-shadow:3px 3px;设置指定颜色的 水平和垂直阴影
    设置 带模糊距离的 x,y 阴影偏移量 text-shadow:3px 3px 1px green;加大模糊半径 text-shadow:3px 3px 10px green;
    x 阴影偏移量 负值 (向左偏移)y 阴影偏移量 负值 (向上偏移)
  • 同时设置: x,y 阴影偏移量 必须同时设置,只设置一个 没效果,没阴影.
  • 文本的装饰线 也会出现阴影  

  • 15. CSS3 text-wrap 属性: 文本换行 (浏览器 都不支持)



  • ② 不换行。
  • ③ 任意处换行。
  • ④ 压缩换行。

  • 16. unicode-bidi 属性: 双向文本的 重写/覆盖 (搭配 direction 属性)

  • 覆盖 浏览器算法: unicode-bidi 属性 覆盖了 这个 Unicode统一码算法,允许开发人员 控制文本嵌入。
  • 不受all属性影响: unicode-bidi 与 direction 是仅有的两个 不受 all 属性 影响的属性。

  • /* 关键字值 Keyword values */unicode-bidi: normal;unicode-bidi: embed;unicode-bidi: isolate;unicode-bidi: bidi-override;unicode-bidi: isolate-override;unicode-bidi: plaintext;/* 全局值 Global values */unicode-bidi: inherit;unicode-bidi: initial;unicode-bidi: unset;

  • 对于内联元素: 隐式重新排序 可以 跨元素边界 进行
  • ② 嵌入,不覆盖/重写: embed    
  • 嵌入层的方向: 由方向direction 属性给出。
  • ③ 按照方向 严格覆盖/重写: bidi-override    
  • 块容器元素      
  • 即 在元素内部,根据 方向direction属性 严格 按顺序 重新排序;
  • 3个新属性值: 下面的属性值 浏览器支持度 不是很好,需要浏览器前缀
  • ④ isolate    
  • ⑤ isolate-override    
  • ⑥ plaintext    


  • 文本流向 左到右时 direction: ltr;文本流向 右到左时: direction: rtl; (配 normal 值)
    嵌入,不重写/覆盖 unicode-bidi: embed;嵌入,严格重写/覆盖 unicode-bidi: bidi-override;

    17. CSS3 word-break 属性: 单词 换行/断行 位置 (能否 词内断行)


    /* 关键字值 Keyword values */word-break: normal; word-break: break-all; word-break: keep-all;word-break: break-word; /* deprecated 已废弃 *//* 全局值 Global values */word-break: inherit;word-break: initial;word-break: unset;

  • 任意处/词内 断行(非中日韩文本):break-all    
  • 不能 词内断行: keep-all    
  • 非中日韩 Non-CJK 文本: 表现 同 浏览器默认行为 normal。
  • 单词处 断行: break-word    


  • .wordbreak{    width: 30%;    background-color: #d0d0d0;    padding: 10px;	    border: solid black 2px;    font-size: 1.2em;	    /*单词换行处 设置*/    word-break: normal;    /*word-break: break-all;*/    /*word-break: keep-all;*/    /*word-break: break-word;*/}
        <p>金无足赤,人无完人。出自宋·戴复古《寄兴》:“黄金无足色,白璧有微瑕。求人不求备,妾愿老君家。” 也比喻不能要求一个人没有一点缺点错误,应该严以律己,宽以待人。<br>No one is perfect, everyone will make mistakes,be strict with yourself and lenient toward others.</p>
    默认显示 = word-break: normal;任意处断行(可单词内断行) word-break: break-all;
    不能单词内断行 (中日韩 不断行) word-break: keep-all;单词处断行 = = word-break: normal;

    18. CSS3 word-wrap / overflow-wrap 属性: 单词 断行时的 断行位置 (断句/断行 方式)

  • 重命名和别名:

  • 别名: word-wrap 现在被当作 overflow-wrap 的 “别名”。
  • 优先使用 word-wrap 属性名,目前 浏览器支持度更好些.

  • /* 关键字值 Keyword values */overflow-wrap: normal;overflow-wrap: break-word;overflow-wrap: anywhere;/* 全局值 Global values */overflow-wrap: inherit;overflow-wrap: initial;overflow-wrap: unset;

  • 可能会出现 文本溢出.
  • (溢出的)长单词/长中文句子 强制分割: break-word    
  • 不会出现 文本溢出.
  • 任意处断行(防溢出): anywhere (浏览器支持度 很差,不要使用)

  • word-break强调的是: 能否 单词内的断句,范围是 全部文本.
  • word-wrap 强调的是: 单词内 断句方式,范围是 需要断句的文本.
  • 长单词 强行断句    
  • ② 不同点: 会不会 开始一个新行


  • .wordbreak{    width: 20%;    background-color: #d0d0d0;    padding: 10px;	    border: solid black 2px;    font-size: 1.2em;	    /*单词换行处 设置*/    /*word-break: normal;*/    /*word-break: break-all;*/    /*word-break: keep-all;*/    /*word-break: break-word;*/}.wordwrap{        /*单词 断行位置*//*word-wrap: normal;*/    /*word-wrap: break-word;*/}
        <p>金无足赤,人无完人。出自宋·戴复古《寄兴》:“黄金无足色,白璧有微瑕。求人不求备,妾愿老君家。” 也比喻不能要求一个人没有一点缺点错误,应该严以律己,宽以待人。<br> No one is perfect, everyone will make mistakes,be strict with yourself and lenient toward others.Nooneisperfecteveryonewillmakemistakes</p>
    可词内断行 word-break: break-all;长单词 强制断行 word-wrap: break-word;
    不允许 词内断行 word-break: keep-all;同时设置 不允许 词内断行 word-break: keep-all; 和 强制长单词 断行 word-wrap: break-word;
  • ② 同时设置 不允许 词内断行 word-break: keep-all; 和 强制长单词 断行 word-wrap: break-word;  

  • 19. word-spacing 属性: 单词/字 之间的 距离

  • 设置元素中 字之间 插入多少空白符。

  • /* 关键字值 Keyword value */word-spacing: normal;/* 长度值 <length> values */word-spacing: 3px;word-spacing: 0.3em;/* 百分比值 <percentage> values */word-spacing: 50%;word-spacing: 200%;/* 全局值 Global values */word-spacing: inherit;word-spacing: initial;word-spacing: unset;</percentage></length>

  • 额外 单词间距: 长度值: length    
  • 额外 单词间距: 百分比值: (浏览器支持度很差,勿用)
  • 继承父亲: inherit    
  • 负值: 让字/单词之间 挤得更紧,缩短 单词/字 之间的距离


  • .wordspace {    width: 25%;    background-color: #d0d0d0;    padding: 10px;    border: solid black 2px;    font-size: 1.1em;        /*设置单词/字 之间的距离*/    word-spacing: normal;    /*word-spacing:4px;*/    /*word-spacing:-4px;*/    /*word-spacing:1em;*/    /*word-spacing:-1em;*/    /*百分比值 目前各大主流浏览器 不支持*/    /*word-spacing:10%;*/}
        <p>金无 足赤,人无 完人。比喻 不能要求一个人 没有一点缺点错误,应该 严以律己,宽以待人。        <br>No one is perfect, everyone will make mistakes,be strict with yourself and lenient toward others.</p>
    单词/字间距 增加 word-spacing:4px;单词/字间距 减少 word-spacing:-4px;
    单词/字间距 增加 word-spacing:1em;单词/字间距 减少 word-spacing:-1em;
  • ② 对于带有较大负值的文本
  • 不同字体 不同单词间距: 清晰的字间距 必须根据具体情况 来确定,因为不同的字体 有不同的 字符宽度。

  • 20. white-space 属性: 空白和换行的 处理


    /* 关键字值 Keyword values */white-space: normal;white-space: nowrap;white-space: pre;white-space: pre-wrap;white-space: pre-line;white-space: break-spaces;/* 全局值 Global values */white-space: inherit;white-space: initial;white-space: unset;

  • 不换行: nowrap    
  • 保留空白/换行 = 预格式: pre    
  • 预格式+自动换行: pre-wrap    
  • 保留换行+自动换行: pre-line    
  • ⑥ break-spaces    
  • 继承父亲: inherit    

  • 属性值换行空格和制表符自动换行行尾空格
    normal合并合并自动换行删除
    nowrap合并合并不自动换行删除
    pre保留保留不自动换行保留
    pre-wrap保留保留自动换行Hang
    pre-line保留合并自动换行删除
    break-spaces保留保留自动换行Wrap 保留的空格字符后 都存在换行机会

  • pre 和 pre-wrap的 区别

  • pre 和 pre-line的 区别

  • 不换行 nowrap 和 预格式 pre的共同点


  • @@##@@


    .whitespace{width: 25%;    background-color: #d0d0d0;    padding: 10px;	    border: solid black 2px;    font-size: 1.1em;	    white-space:normal;    white-space:nowrap;    white-space:pre;    white-space:pre-wrap;    white-space:pre-line;    /*white-space:break-space;*/}
        <p>         <strong>                《题乌江亭》      </strong>                                 唐代·杜牧         <b>胜败兵家事不期,包羞忍耻是男儿。</b>         <b>江东子弟多才俊,卷土重来未可知。</b>         <br>        译文: 胜败乃是兵家常事,难以事前预料。能够忍辱负重,才是真正男儿。        西楚霸王啊,江东子弟人才济济,若能重整旗鼓卷土杀回,楚汉相争,谁输谁赢还很难说。    </p>
    不换行 white-space:nowrap;预格式 保留空格和换行 white-space:pre;
    预格式+自动换行 white-space:pre-wrap;只保留换行+自动换行 white-space:pre-line;

    (学习视频分享:web前端入门)