文本缩进(对p,div有效;对span无效)

  1. p {text-indent: 5em;}

Tips:一般来说,可以为所有块级元素应用 text-indent,但无法将该属性应用于行内元素(span),图像之类的替换元素上也无法应用 text-indent 属性。不过,如果一个块级元素(比如段落)的首行中有一个图像,它会随该行的其余文本移动。

使用百分比

text-indent 可以使用所有长度单位,包括百分比值。

百分数要相对于缩进元素父元素的宽度。换句话说,如果将缩进值设置为 20%,所影响元素的第一行会缩进其父元素宽度的 20%。

在下例中,缩进值是父元素的 20%,即 100 个像素:

  1. div {width: 500px;}
  2. p {text-indent: 20%;}
  3. <div>
  4. <p>this is a paragragh</p>
  5. </div>

继承

text-indent 属性可以继承

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. div#outer {width: 500px;background-color:red;}
  5. div#inner {text-indent: 10%;}
  6. p {width: 200px;}
  7. </style>
  8. </head>
  9. <body>
  10. <div id="outer">
  11. <div id="inner">some text. some text. some text.
  12. <p>this is a paragragh.</p>
  13. </div>
  14. </div>
  15. </body>
  16. </html>

text-align ,对行内元素span无效。

Tips:将块级元素或表元素居中,要通过在这些元素上适当地设置左、右外边距来实现。

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. div {width:500px;background-color:red;}
  5. p {text-align:center;}
  6. </style>
  7. </head>
  8. <body>
  9. <div>
  10. <p>this is a paragragh.</p>
  11. </div>
  12. </body>
  13. </html>

基于父元素居中,对行内元素无效。

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. div {width:500px;background-color:red;}
  5. span {text-align:center;display:block;}
  6. </style>
  7. </head>
  8. <body>
  9. <div>
  10. <span>this is a paragragh.</span>
  11. </div>
  12. </body>
  13. </html>

Span加上display:block;就能变为块状元素。

word-spacing

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. span.spread {word-spacing: 10px;}
  5. p.tight {word-spacing: -0.5em;}
  6. </style>
  7. </head>
  8. <body>
  9. <span class="spread">This is some text. This is some text.</span>
  10. <p class="tight">This is some text. This is some text.</p>
  11. </body>
  12. </html>

与行内元素,块状元素都有效。

text-transform

  1. none
  2. uppercase
  3. lowercase
  4. capitalize

不变动,全部大写,全部小写,首字母大写。

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. h1 {text-transform: uppercase}
  5. span.uppercase {text-transform: uppercase}
  6. p.lowercase {text-transform: lowercase}
  7. p.capitalize {text-transform: capitalize}
  8. </style>
  9. </head>
  10. <body>
  11. <h1>This Is An H1 Element</h1>
  12. <span class="uppercase">This is some text in a paragraph.</span>
  13. <p class="lowercase">This is some text in a paragraph.</p>
  14. <p class="capitalize">This is some text in a paragraph.</p>
  15. </body>
  16. </html>

对行内元素,块状元素都有效。

文本装饰

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. p.none {text-decoration: none}
  5. span.underline {text-decoration: underline}
  6. p.overline {text-decoration: overline}
  7. p.line-through {text-decoration: line-through}
  8. p.blink {text-decoration: blink}
  9. </style>
  10. </head>
  11. <body>
  12. <p class="none">This is some text in a paragraph.</p>
  13. <span class="underline">This is some text in a paragraph.</span>
  14. <p class="overline">This is some text in a paragraph.</p>
  15. <p class="line-through">This is some text in a paragraph.</p>
  16. <p class="blink">This is some text in a paragraph.</p>
  17. </body>
  18. </html>

blink是让文本闪烁,浏览器不一定支持。

white-space

对源文档中的空格、换行和 tab 字符的处理。

  1. p {white-space: normal;}

上面的规则告诉浏览器按照平常的做法去处理:丢掉多余的空白符。如果给定这个值,换行字符(回车)会转换为空格,一行中多个空格的序列也会转换为一个空格。

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. p {white-space: normal;}
  5. </style>
  6. </head>
  7. <body>
  8. <p>This paragraph has many
  9. spaces in it.</p>
  10. <p>注释:当 white-space 属性设置为 normal 时,会合并所有的空白符,并忽略换行符。</p>
  11. </body>
  12. </html>
描述
normal 默认。空白会被浏览器忽略。
pre 空白会被浏览器保留。其行为方式类似 HTML 中的
  1. 标签。
nowrap 文本不会换行,文本会在在同一行上继续,直到遇到
标签为止。
pre-wrap 保留空白符序列,但是正常地进行换行。
pre-line 合并空白符序列,但是保留换行符。
inherit 规定应该从父元素继承 white-space 属性的值。
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. p {white-space: pre-line;}
  5. </style>
  6. </head>
  7. <body>
  8. <p>This paragraph has a great many s p a c e s with
  9. its textual content, but their collapse will not prevent
  10. line wrapping or line breaking.</p>
  11. <p>注释:当 white-space 属性设置为 pre-line 时,浏览器会保留换行符,并允许自动换行,但是会合并空白符,这是与 pre-wrap 值的不同之处。</p>
  12. </body>
  13. </html>
空白符 换行符 自动换行
pre-line 合并 保留 允许
normal 合并 忽略 允许
nowrap 合并 忽略 不允许
pre 保留 保留 不允许
pre-wrap 保留 保留 允许

CSS 再学习,文本处理的更多相关文章

  1. CSS 3学习——文本效果和@font-face

    文本效果 关于文本效果,这里仅仅记录得到大多数浏览器支持的几个属性,分别是: text-overflow text-shadow word-break word-wrap text-overflow ...

  2. CSS再学习 之背景色 背景图片

    背景色 p {background-color: gray;} 如果您希望背景色从元素中的文本向外少有延伸,只需增加一些内边距. p {background-color: gray; padding: ...

  3. CSS 再学习,基础篇

    语法 h1 {color:red; font-size:14px;} 共享声明 h1,h2,h3,h4,h5,h6 { color: green; } 继承 通过 CSS 继承,子元素将继承最高级元素 ...

  4. 学习笔记 第五章 使用CSS美化网页文本

    第五章   使用CSS美化网页文本 学习重点 定义字体类型.大小.颜色等字体样式: 设计文本样式,如对齐.行高.间距等: 能够灵活设计美观.实用的网页正文版式. 5.1 字体样式 5.1.1 定义字体 ...

  5. HTML/CSS/JavaScript学习总结(转)

    HTML 网站开发的主要原则是: – 用标签元素HTML描述网页的内容结构: – 用CSS描述网页的排版布局: – 用JavaScript描述网页的事件处理,即鼠标或键盘在网页元素上的动作后的程序 H ...

  6. (2)《Head First HTML与CSS》学习笔记---img与基于标准的HTML5

    1.浏览器处理图像的过程: 1.服务器获取文件,显示出文本结构,以及预留默认的大小给<img>(如果该<img>有width-1值和height-1值,则根据这个值提前设好页面 ...

  7. (6)《Head First HTML与CSS》学习笔记---结尾、《HTML5权威指南》读书笔记

    1.内联元素的外边距.内边距与块元素稍有不同. 如果一个内联元素四周都增加外边距,只能看到左边和右边会增加空间:你也可以对内联元素的上下增加内边距,不过这个内边距不会影响包围它的其他内联元素的间距—— ...

  8. CSS入门级学习

    css入门学习1:认识CSS 1.1:css简介,css全称是层叠样式表,Cascading style sheets 1.2:css的作用,主要是用于定义html内容在浏览器内的显示样式,如文字大小 ...

  9. HTML&CSS基础学习笔记—创建列表

    创建一张表格 很多时候我们需要在网页上展示一些数据,使用表格可以很好的来展示数据. 在HTML中<table>标签定义 表格. <table> </table> 添 ...

随机推荐

  1. Linux常用命令大全(转载)

    最近都在和Linux打交道,这方面基础比较薄弱的我只好买了本鸟哥的书看看,感觉还不错.我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因, ...

  2. 【巷子】---vue项目打包---基本使用---【vue】

    一.基本设置 二.打包 npm run build 三.github创建一个仓库 1.将文件上传至仓库 2.点击仓库设置 3.选择代码上传到master 4.点击地址即可预览 5.常用技巧 a.如果在 ...

  3. 自定义一个ListView实现聊天界面

    摘要 ListView可以称得上Android中最常用也最难用的控件了,几乎所有的应用程序都会用到它.由于手机屏幕空间都比较有限,能够一次性在屏幕上显示的内容并不多,当我们的程序中有大量的数据需要展示 ...

  4. Windows安装使用git

    下载安装Windows安装文档Git-2.16.2-64-bit双击安装(安装过程不详述) 打开git客户端 新建代码命令 mkdir /c/code 进入该目录(对应windows的c盘下面的目录) ...

  5. Python开发【Django】:基础

    Django基本配置 Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Se ...

  6. PostgreSQL数据库的安装与PostGIS的安装(转)

    原文:http://lovewinner.iteye.com/blog/1490915 安装postgresql sudo apt-get install postgresql-9.1 postgre ...

  7. 省市县三级联动的SQL

    完整版见https://jadyer.github.io/ 首先是建表语句 CREATE TABLE `t_address_province` ( `id` INT AUTO_INCREMENT PR ...

  8. centos 阶段复习 2015-4-6 dd命令 hosts.allow和hosts.deny 啊铭的myssh脚本 清空history命令历史 /dev/zero 零发生器 /dev/null 黑洞 /dev/random 生成随机数 第十一节课

    centos 阶段复习 2015-4-6  dd命令 hosts.allow和hosts.deny 啊铭的myssh脚本 清空history命令历史  /dev/zero 零发生器  /dev/nul ...

  9. (转) 密码学中的“盐值 Salt”

    为什么要在密码里加点“盐” 盐(Salt) 在密码学中,是指通过在密码任意固定位置插入特定的字符串,让散列后的结果和使用原始密码的散列结果不相符,这种过程称之为“加盐”. 以上这句话是维基百科上对于 ...

  10. mysql锁机制之综述(一)

    https://zhuanlan.zhihu.com/p/29150809 一.数据库有锁机制的原因. 数据库锁定机制简单来说,就是数据库为了保证数据的一致性和有效性,而使各种共享资源在被并发访问变得 ...