• CSS Text(文本)


    CSS Text(文本)

    一、文本颜色

    color 颜色属性被用来设置文字的颜色。

    颜色是通过CSS最经常的指定:

    • 十六进制值 - 如: #FF0000
    • 一个RGB值 - 如: RGB(255,0,0)
    • 颜色的名称 - 如: red

    一个网页的背景颜色是指在主体内的选择:

    body {color:red;}
    h1 {color:#00ff00;}
    h2 {color:rgb(255,0,0);}

    注意:对于W3C标准的CSS:如果你定义了颜色属性,你还必须定义背景色属性。

    二、文本的对齐方式

    text-align 文本排列属性是用来设置文本的水平对齐方式。

    文本可居中或对齐到左或右,两端对齐.

    当text-align设置为"justify",每一行被展开为宽度相等,左,右外边距是对齐(如杂志和报纸)。

    h1 {text-align:center;}
    p.date {text-align:right;}
    p.main {text-align:justify;}

    示例代码:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8"> 
    <title>css教程</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> 重置浏览器窗口大小查看 &quot;justify&quot; 是如何工作的。</p>
    </body>
    </html>

    效果:

    三、文本修饰

    text-decoration 属性用来设置或删除文本的装饰。

    从设计的角度看 text-decoration属性主要是用来删除链接的下划线:

    a {text-decoration:none;}

    也可以这样装饰文字:

    h1 {text-decoration:overline;}
    h2 {text-decoration:line-through;}
    h3 {text-decoration:underline;}

    示例代码:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8"> 
    <title>css教程</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>

    效果:

    注意:我们不建议强调指出不是链接的文本,因为这常常混淆用户。

     四、文本转换

    text-transform 文本转换属性是用来指定在一个文本中的大写和小写字母。

    可用于所有字句变成大写或小写字母,或每个单词的首字母大写。

    p.uppercase {text-transform:uppercase;} /*转为大写*/
    p.lowercase {text-transform:lowercase;} /*转为小写*/
    p.capitalize {text-transform:capitalize;} /*转为每个单词首字母大写*/

    五、文本缩进

    text-indent 文本缩进属性是用来指定文本的第一行的缩进。

    p {text-indent:50px;}

    六、设置字符间距

    letter-spacing 如何增加或减少字符之间的空间。

    h1 {letter-spacing:2px;} /*字符之间增加空间*/
    h2 {letter-spacing:-3px;} /*字符之间减少空间*/

    七、设置行间距

    line-height 指定行与行之间的空间。

    p.small {line-height:70%;}
    p.big {line-height:200%;}

    八、设置元素文本方向

    direction 改变元素的文本方向。

    div.ex1 {direction:rtl;}

    示例代码:

    <html>
    <head>
    <meta charset="utf-8"> 
    <title>css教程</title> 
    <style type="text/css">
    div.ex1 {direction:rtl;}
    </style>
    </head>
    <body>
    <div>一些文本。 默认书写方向</div>
    <div class="ex1">一些文本。从右到左的书写方向</div>
    </body>
    </html>

    效果:

    九、单词之间的空白空间

    word-spacing 增加单词之间的空白空间。

    p
    { 
        word-spacing:30px;
    }

    十、在元素内禁用文件环绕(设置元素中空白的处理方式)

    white-space 如何禁用一个元素内的文字环绕(设置元素中空白的处理方式)。

    p
    {
        white-space:nowrap;
    }

    十一、垂直对齐图像

    vertical-align 如何设置文本的垂直对齐图像。

    img.top {vertical-align:text-top;}
    img.bottom {vertical-align:text-bottom;}

    效果如图:

    十二、设置文本阴影

    text-shadow 设置文本阴影。

    h1 {text-shadow:2px 2px #FF0000;}

    效果如图:

    注意: Internet Explorer 9 以及更早的浏览器不支持 text-shadow 属性。

    十三、所有CSS文本属性

  • 相关阅读:
    506. Relative Ranks
    504. Base 7
    503. Next Greater Element II
    501. Find Mode in Binary Search Tree
    500. Keyboard Row
    1268. Search Suggestions System
    原生 JavaScript 代替 jQuery【转】
    TP5 Request 请求对象【转】
    tp5中使用原生sql查询总结【转】
    成功安装mysql后,为何服务管理器里找不到MYSQL服务名【转】
  • 原文地址:https://www.cnblogs.com/lizm166/p/9344766.html
Copyright © 2020-2023  润新知