小白教程
所有教程
关于
Search
172.70.127.8
172.70.127.8
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“CSS Text(文本)”的源代码
本页内容
上一节:
CSS_Backgrounds(背景)
下一节:
CSS_Fonts(字体)
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:CSS Text(文本)}}[[Category:CSS 教程|7]] = CSS 文本格式 = = 文本格式 = This text is styled with some of the text formatting properties. The heading uses the text-align, text-transform, and color properties. The paragraph is indented, aligned, and the space between characters is specified. The underline is removed from the <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> h1 { text-align: center; text-transform: uppercase; color: #A7C942; } p { text-indent: 50px; text-align:justify; letter-spacing:3px; } a { text-decoration:none; } </style> </head> <body> <h1>text formatting</h1> <p>This text is styled with some of the text formatting properties. The heading uses the text-align, text-transform, and color properties. The paragraph is indented, aligned, and the space between characters is specified. The underline is removed from the <a target="_blank" href="#">"尝试一下"</a> link.</p> </body> </html> </run> link. == 文本颜色 == 颜色属性被用来设置文字的颜色。 颜色是通过CSS最经常的指定: * 十六进制值 - 如: '''#FF0000''' * 一个RGB值 - 如: '''RGB(255,0,0)''' * 颜色的名称 - 如: '''red''' 参阅 [[css colors legal|CSS 颜色值]] 查看完整的颜色值。 一个网页的背景颜色是指在主体内的选择: <sample title="" desc="" lang="html" hererun="1"> body {color:red;} h1 {color:#00ff00;} h2 {color:rgb(255,0,0);} </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> body {color:red;} h1 {color:#00ff00;} p.ex {color:rgb(0,0,255);} </style> </head> <body> <h1>这是标题 1</h1> <p>这是一个普通的段落。请注意,本文是红色的。页面中定义默认的文本颜色选择器。</p> <p class="ex">这是一个类为"ex"的段落。这个文本是蓝色的。</p> </body> </html> </run> 对于W3C标准的CSS:如果你定义了颜色属性,你还必须定义背景色属性。 == 文本的对齐方式 == 文本排列属性是用来设置文本的水平对齐方式。 文本可居中或对齐到左或右,两端对齐. 当text-align设置为"justify",每一行被展开为宽度相等,左,右外边距是对齐(如杂志和报纸)。 <sample title="" desc="" lang="html" hererun="1"> h1 {text-align:center;} p.date {text-align:right;} p.main {text-align:justify;} </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> h1 {text-align:center;} p.date {text-align:right;} p.main {text-align:justify;} </style> </head> <body> <h1>CSS text-align 实例</h1> <p class="date">2015 年 3 月 14 号</p> <p class="main">“当我年轻的时候,我梦想改变这个世界;当我成熟以后,我发现我不能够改变这个世界,我将目光缩短了些,决定只改变我的国家;当我进入暮年以后,我发现我不能够改变我们的国家,我的最后愿望仅仅是改变一下我的家庭,但是,这也不可能。当我现在躺在床上,行将就木时,我突然意识到:如果一开始我仅仅去改变我自己,然后,我可能改变我的家庭;在家人的帮助和鼓励下,我可能为国家做一些事情;然后,谁知道呢?我甚至可能改变这个世界。”</p> <p><b>注意:</b> 重置浏览器窗口大小查看 "justify" 是如何工作的。</p> </body> </html> </run> == 文本修饰 == text-decoration 属性用来设置或删除文本的装饰。 从设计的角度看 text-decoration属性主要是用来删除链接的下划线: <sample title="" desc="" lang="html" hererun="1"> a {text-decoration:none;} </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> a {text-decoration:none;} </style> </head> <body> <p>链接到: <a href="http://www.xiaobai.wang/">xiaobai.wang</a></p> </body> </html> </run> 也可以这样装饰文字: <sample title="" desc="" lang="html" hererun="1"> h1 {text-decoration:overline;} h2 {text-decoration:line-through;} h3 {text-decoration:underline;} </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> h1 {text-decoration:overline;} h2 {text-decoration:line-through;} h3 {text-decoration:underline;} </style> </head> <body> <h1>This is heading 1</h1> <h2>This is heading 2</h2> <h3>This is heading 3</h3> </body> </html> </run> 我们不建议强调指出不是链接的文本,因为这常常混淆用户。 == 文本转换 == 文本转换属性是用来指定在一个文本中的大写和小写字母。 可用于所有字句变成大写或小写字母,或每个单词的首字母大写。 <sample title="" desc="" lang="html" hererun="1"> p.uppercase {text-transform:uppercase;} p.lowercase {text-transform:lowercase;} p.capitalize {text-transform:capitalize;} </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p.uppercase {text-transform:uppercase;} p.lowercase {text-transform:lowercase;} p.capitalize {text-transform:capitalize;} </style> </head> <body> <p class="uppercase">This is some text.</p> <p class="lowercase">This is some text.</p> <p class="capitalize">This is some text.</p> </body> </html> </run> == 文本缩进 == 文本缩进属性是用来指定文本的第一行的缩进。 <sample title="" desc="" lang="html" hererun="1"> p {text-indent:50px;} </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p {text-indent:50px;} </style> </head> <body> <p>In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.'</p> </body> </html> </run> == 更多实例 == [[try.php?filename=trycss_letter spacing|指定字符之间的空间]] 这个例子演示了如何增加或减少字符之间的空间。 [[try.php?filename=trycss_line height|指定行与行之间的空间]] 这个例子演示了如何指定在一个段落中行之间的空间 [[try.php?filename=trycss_text direction|设置元素的文本方向]] 这个例子演示了如何改变元素的文本方向。 [[try.php?filename=trycss_text word spacing|增加单词之间的空白空间]] 这个例子演示了如何增加一个段落中的单词之间的空白空间。 [[try.php?filename=trycss_text white space|在元素内禁用文字环绕]] 这个例子演示了如何禁用一个元素内的文字环绕。 [[try.php?filename=trycss_vertical align|垂直对齐图像]] 这个例子演示了如何设置文本的垂直对齐图像。 [[try.php?filename=trycss_text shadow|添加文本阴影]] 这个例子演示了如何设置文本阴影。 == 所有CSS文本属性。 == {| class="table table-striped table-hover" ! 属性 ! 描述 |- | [[pr text color|color]] | 设置文本颜色 |- | [[pr text direction|direction]] | 设置文本方向。 |- | [[pr text letter spacing|letter-spacing]] | 设置字符间距 |- | [[pr dim line height|line-height]] | 设置行高 |- | [[pr text text align|text-align]] | 对齐元素中的文本 |- | [[pr text text decoration|text-decoration]] | 向文本添加修饰 |- | [[pr text text indent|text-indent]] | 缩进元素中文本的首行 |- | [[css3 pr text shadow|text-shadow]] | 设置文本阴影 |- | [[pr text text transform|text-transform]] | 控制元素中的字母 |- | [[pr text unicode bidi|unicode-bidi]] | 设置或返回文本是否被重写 |- | [[pr pos vertical align|vertical-align]] | 设置元素的垂直对齐 |- | [[pr text white space|white-space]] | 设置元素中空白的处理方式 |- | [[pr text word spacing|word-spacing]] | 设置字间距 |}
返回至“
CSS Text(文本)
”。
上一节:
CSS_Backgrounds(背景)
下一节:
CSS_Fonts(字体)