CSS 文本实例

CSS 实例

  • CSS 背景实例
  • CSS 文本实例
  • CSS 字体(font)实例
  • CSS 边框(border)实例
  • CSS 外边距 (margin) 实例
  • CSS 内边距 (padding) 实例
  • CSS 列表实例
  • CSS 表格实例
  • 轮廓(Outline) 实例
  • CSS 尺寸 (Dimension) 实例
  • CSS 分类 (Classification) 实例
  • CSS 定位 (Positioning) 实例
  • CSS 伪类 (Pseudo-classes)实例
  • CSS 伪元素 (Pseudo-elements)实例

01设置文本颜色

<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>01设置文本颜色</title>
<style type="text/css">
body {
background-color: #C7FFEC;
color: #536D8A;
}
h1 {
color: #D6BCFF;
}
p.mm {
color: #AD9876;
}
</style>
</head> <body>
<h1>我是heading 1。</h1>
<p>我是一个段落。</p>
<p class="mm">我是另外一个定义了"mm"类的段落。</p>
</body> </html>


02设置文本的背景颜色

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>02设置文本的背景颜色</title>
<style type="text/css">
body {
background-color: #C7FFEC;
}
span.highlight {
background-color: #81FF38;
}
</style>
</head>
<body>
<p>
<span class="highlight">这是文本。</span> 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 这是文本。 <span class="highlight">这是文本。</span>
</p>
</body>
</html>


03规定字符间距

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>03规定字符间距</title>
<style type="text/css">
body {
background-color: #C7FFEC;
}
h1 {
letter-spacing: -0.5em;
}
h4 {
letter-spacing: 20px;
}
</style>
</head>
<body>
<h1>我是标题1,This is header 1。</h1>
<h4>我是标题4,This is header 4。</h4>
</body>
</html>


04使用百分比设置行间距

<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>04使用百分比设置行间距</title>
<style type="text/css">
body{
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151205145324174-1406078733.gif);
color: #008A83;
}
p.big{line-height: 200%;}
p.small{line-height: 90%;}
span.highlight{background-color: #D8B36E;}
</style>
</head> <body>
<p>
<span class="highlight">这个段落是标准行高。</span>
<br /> When you are old and grey and full of sleep,
<br /> 当你老了,头发花白,睡意沉沉,
<br /> And nodding by the fire,take down this book,
<br /> 倦坐在炉边,取下这本书来,
<br /> And slowly read,and dream of the soft look,
<br /> 慢慢读着,追梦当年的眼神,
<br /> Your eyes had once,and of their shadows deep;
<br /> 你那柔美的神采与深幽的晕影。
</p>
<p class="small">
<span class="highlight">这个段落的行高较小。</span>
<br /> How many loved your moments of glad grace,
<br /> 多少人爱过你昙花一现的身影,
<br /> And loved your beauty with love false or true,
<br /> 爱过你的美貌,以虚伪或真情,
<br /> But one man loved the pilgrim Soul in you,
<br /> 惟独一人曾爱你那朝圣者的心,
<br /> And loved the sorrows of your changing face;
<br /> 爱你哀戚的脸上岁月的留痕。
</p>
<p class="big">
<span class="highlight">这个段落的行高较大。</span>
<br /> And bending down beside the glowing bars,
<br /> 在炉罩边低眉弯腰,
<br /> Murmur,a little sadly,how Love fled,
<br /> 忧戚沉思,喃喃而语,
<br /> And paced upon the mountains overhead,
<br /> 爱情是怎样逝去,又怎样步上群山,
<br /> And hid his face amid a crowd of stars.
<br /> 怎样在繁星之间藏住了脸。
</p>
</body> </html>


05使用像素值设置行间距

<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>05使用像素值设置行间距</title>
<style type="text/css">
body{
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151205145324174-1406078733.gif);
color: #008A83;
}
p.big{line-height: 30px;}
p.small{line-height: 10px;}
span.highlight{background-color: #D8B36E;}
</style>
</head> <body>
<p>
<span class="highlight">这个段落是标准行高。</span>
<br /> When you are old and grey and full of sleep,
<br /> 当你老了,头发花白,睡意沉沉,
<br /> And nodding by the fire,take down this book,
<br /> 倦坐在炉边,取下这本书来,
<br /> And slowly read,and dream of the soft look,
<br /> 慢慢读着,追梦当年的眼神,
<br /> Your eyes had once,and of their shadows deep;
<br /> 你那柔美的神采与深幽的晕影。
</p>
<p class="small">
<span class="highlight">这个段落的行高较小。</span>
<br /> How many loved your moments of glad grace,
<br /> 多少人爱过你昙花一现的身影,
<br /> And loved your beauty with love false or true,
<br /> 爱过你的美貌,以虚伪或真情,
<br /> But one man loved the pilgrim Soul in you,
<br /> 惟独一人曾爱你那朝圣者的心,
<br /> And loved the sorrows of your changing face;
<br /> 爱你哀戚的脸上岁月的留痕。
</p>
<p class="big">
<span class="highlight">这个段落的行高较大。</span>
<br /> And bending down beside the glowing bars,
<br /> 在炉罩边低眉弯腰,
<br /> Murmur,a little sadly,how Love fled,
<br /> 忧戚沉思,喃喃而语,
<br /> And paced upon the mountains overhead,
<br /> 爱情是怎样逝去,又怎样步上群山,
<br /> And hid his face amid a crowd of stars.
<br /> 怎样在繁星之间藏住了脸。
</p>
</body> </html>


06使用数值来设置行间距

<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>06使用数值来设置行间距</title>
<style type="text/css">
body{
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151205145324174-1406078733.gif);
color: #008A83;
}
p.big{line-height: 2;}
p.small{line-height: 0.5;}
span.highlight{background-color: #D8B36E;}
</style>
</head> <body>
<p>
<span class="highlight">这个段落是标准行高。</span>
<br /> When you are old and grey and full of sleep,
<br /> 当你老了,头发花白,睡意沉沉,
<br /> And nodding by the fire,take down this book,
<br /> 倦坐在炉边,取下这本书来,
<br /> And slowly read,and dream of the soft look,
<br /> 慢慢读着,追梦当年的眼神,
<br /> Your eyes had once,and of their shadows deep;
<br /> 你那柔美的神采与深幽的晕影。
</p>
<p class="small">
<span class="highlight">这个段落的行高较小。</span>
<br /> How many loved your moments of glad grace,
<br /> 多少人爱过你昙花一现的身影,
<br /> And loved your beauty with love false or true,
<br /> 爱过你的美貌,以虚伪或真情,
<br /> But one man loved the pilgrim Soul in you,
<br /> 惟独一人曾爱你那朝圣者的心,
<br /> And loved the sorrows of your changing face;
<br /> 爱你哀戚的脸上岁月的留痕。
</p>
<p class="big">
<span class="highlight">这个段落的行高较大。</span>
<br /> And bending down beside the glowing bars,
<br /> 在炉罩边低眉弯腰,
<br /> Murmur,a little sadly,how Love fled,
<br /> 忧戚沉思,喃喃而语,
<br /> And paced upon the mountains overhead,
<br /> 爱情是怎样逝去,又怎样步上群山,
<br /> And hid his face amid a crowd of stars.
<br /> 怎样在繁星之间藏住了脸。
</p>
</body> </html>


07对齐文本

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>07对齐文本</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151205221342736-660016724.jpg);
color: #CE790E;
}
h1 {text-align: center;}
h2 {text-align: left;}
h3 {text-align: right;}
</style>
</head>
<body>
<h1>我居中</h1>
<h2>我居左</h2>
<h3>我居右</h3>
</body>
</html>


08修饰文本

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>08修饰文本</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151206101318236-1435797598.jpg);
}
h1 {text-decoration: overline;}
h2 {text-decoration: line-through;}
h3 {text-decoration: underline;}
h4 {text-decoration: blink;}
a {text-decoration: none;} </style>
</head>
<body>
<h1>我是标题1</h1>
<h2>我是标题2</h2>
<h3>我是标题3</h3>
<h4>我是标题4</h4>
<a>我是一个链接</a>
</body>
</html>


09缩进文本

<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>09缩进文本</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151206115736205-1795690586.jpg);
color: #EAF786;
}
p {text-indent: 1cm;}
</style>
</head> <body>
<p>
一切都是命运,一切都是烟云,一切都是没有结局的开始,一切都是稍纵即逝的追寻,一切欢乐都没有微笑,一切苦难都没有泪痕,一切语言都是重复,一切交往都是初逢,一切爱情都在心里,一切往事都在梦中,一切希望都带着注释,一切信仰都带着呻吟,一切爆发都有片刻的宁静,一切死亡都有冗长的回声。
</p>
</body> </html>


10控制文本中的字母

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>10控制文本中的字母</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151206130923799-1455440074.jpg);
color: #1D4218;
}
h1 {text-transform: uppercase;}
p.uppercase {text-transform: uppercase;}
p.lowercase {text-transform: lowercase;}
p.capitalize {text-transform: capitalize;}
</style>
</head>
<body>
<h1 class="uppercase">Come here and take a lesson from the lovely lemon tree.</h1>
<p class="uppercase">Come here and take a lesson from the lovely lemon tree.</p>
<p class="lowercase">Come here and take a lesson from the lovely lemon tree.</p>
<p class="capitalize">Come here and take a lesson from the lovely lemon tree.</p>
</body>
</html>


11在元素中禁止文本折行

<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>11在元素中禁止文本折行</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151206145148049-841538240.jpg);
}
p {white-space: nowrap;}
</style>
</head>
<body>
<p>
这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。 这是一些文本。
</p>
</body>
</html>


12增加单词间距

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>12增加单词间距</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151206145148049-841538240.jpg);
}
p.spread {word-spacing: 30px;}
p.tight {word-spacing: -0.5em;}
</style>
</head>
<body>
<p class="spread">Those were such happy times.</p>
<p class="tight">Those were such happy times.</p>
</body>
</html>


CSS文本实例总结:

W3School-CSS 文本实例的更多相关文章

  1. CSS文本实例

    CSS 文本属性可定义文本的外观. 通过文本属性,您可以改变文本的颜色.字符间距,对齐文本,装饰文本,对文本进行缩进,等等.#############################CSS 文本属性属 ...

  2. CSS 文本实例

    1.设置文本的颜色 color:red; color:#00ff00 color:rgb(0,0,255) 2.增加或减少字符间距 letter-spacing:-0.5em letter-spaci ...

  3. CSS 文本

    CSS 文本属性可定义文本的外观. 通过文本属性,您可以改变文本的颜色.字符间距,对齐文本,装饰文本,对文本进行缩进,等等. 缩进文本 把 Web 页面上的段落的第一行缩进,这是一种最常用的文本格式化 ...

  4. CSS 文本、字体、链接

    CSS 文本属性可定义文本的外观. 通过文本属性,您可以改变文本的颜色.字符间距,对齐文本,装饰文本,对文本进行缩进,等等. 缩进文本 把 Web 页面上的段落的第一行缩进,这是一种最常用的文本格式化 ...

  5. CSS 文本字体颜色设置方法(CSS color)

    CSS 文本字体颜色设置方法(CSS color) 一.认识CSS 颜色(CSS color) 这里要介绍的是网页设置颜色包含有哪些:网页颜色规定规范. 1.常用颜色地方包含:字体颜色.超链接颜色.网 ...

  6. CSS:CSS 文本格式

    ylbtech-CSS:CSS 文本格式 1.返回顶部 1. CSS 文本格式 文本格式 This text is styled with some of the text formatting pr ...

  7. 第 15 章 CSS 文本样式[下]

    学习要点: 1.文本总汇 2.文本样式 3.文本控制 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 文本样式,通过文本样式的设置,更改字体的大小.样式以及文本的方位. 一.文本总汇 本节课, ...

  8. 第 15 章 CSS 文本样式[上]

    学习要点: 1.字体总汇 2.字体设置 3.Web 字体 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 文本样式,通过文本样式的设置,更改字体的大小.样式以及文本的方位. 一.字体总汇 本节 ...

  9. css文本格式详解

    一.css文本主体内容: 二.css文本详解:  1.文本缩进 语法: text-indent:<length>|<percentage> 默认值为0. 属性值详解: < ...

随机推荐

  1. TINYINT,SMALLINT,MEDIUMINT,INT,INTEGER,BIGINT;text,longtext,mediumtext,ENUM,SET等字段类型区别

    http://www.path8.net/tn/archives/951 MySQL支持大量的列类型,它可以被分为3类:数字类型.日期和时间类型以及字符串(字符)类型.本节首先给出可用类型的一个概述, ...

  2. PYTHON3连接MYSQL数据库

    http://smilejay.com/2013/03/python3-mysql-connector/ Python 2.x 上连接MySQL的库倒是不少的,其中比较著名就是MySQLdb(Djan ...

  3. Firemonkey ListView 点击事件

    Firemonkey ListView 的点击事件一直让人摸不着头绪(各平台触发规则不太相同),因为它提供了点击相关的事件就有如下: OnChange:改变项目触发. OnClick:点击触发. On ...

  4. 最小生成二叉树-prim算法

    1.prim算法:一种计算生成最小生成树的方法,它的每一步都会为一棵生长中的树添加一条边. 2.时间复杂度:

  5. Spring web应用最大的败笔

    第一篇 介绍下IOC DI Spring主要是业务层框架,现在已经发展成为一个完整JavaEE开发框架,它的主要特点是IoC DI和AOP等概念的融合,强项在面向切面AOP.推出之初因为Ioc/AOP ...

  6. 《第一行代码》学习笔记——第1章 开始启程,你的第一行Android代码

    1.3 创建你的第一个Android项目 1.3.1 创建HelloWorld项目 1.Application Name代表应用名称,手机上显示的就是它: 2.Project Name代表项目名称,其 ...

  7. BZOJ 1051 最受欢迎的牛 解题报告

    题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4438  Solved: 2353[S ...

  8. apache maven pom setting

    <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...

  9. [js开源组件开发]数字或金额千分位格式化组件

    数字或金额千分位格式化组件 这次距离上一个组件<[js开源组件开发]table表格组件>时隔了一个月,由于最近的项目比较坑,刚挖完坑,所以来总结性提出来几个组件弥补这次的空缺,首先是金额和 ...

  10. 【Bootstrap】入门例子创建

    本文简单介绍下如何来使用 Bootstrap,通过引入 Bootstrap,来实现一个最基本的入门例子. 在前一篇博文[Bootstrap]1.初识Bootstrap 基础之上,我们完全可以更加方便快 ...