zoukankan      html  css  js  c++  java
  • CSS文本

    1.设置不同元素的文本颜色

    h1 {
        color: lawngreen;
    }
    p{
        color: red;
    }
    p.ex{
        color: rgb(0, 0, 255);
    }
    <body>
        <h1>这是标题1</h1>
        <p>这是一个普通的段落。请注意,文本是红色的。页面中定义默认的文本颜色选择器</p>
        <P class="ex">这是一个类为&quot;ex&quot;的段落。这个文本是蓝色的。</P>
    </body>

    2.文本对齐

    h1 {
        text-align: center;
    }
    p.right {
        text-align: right;
    }
    p.main{
        text-align: justify;
    }
    <body>
       <h1>CSS text-align实例</h1>
       <p class="right">2019年6月1号</p>
       <p class="main">“当我年轻的时候,我梦想改变这个世界;当我成熟以后,我发现我不能够改变这个世界,我将目光缩短了些,决定只改变我的国家;当我进入暮年以后,我发现我不能够改变我们的国家,我的最后愿望仅仅是改变一下我的家庭,但是,这也不可能。当我现在躺在床上,行将就木时,我突然意识到:如果一开始我仅仅去改变我自己,然后,我可能改变我的家庭;在家人的帮助和鼓励下,我可能为国家做一些事情;然后,谁知道呢?我甚至可能改变这个世界。”</p>
       <p><b>注意:</b>重置浏览器窗口大小查看&quot;justify&quot;是如何工作的;</p>
    </body>

    3.移除连接下划线

    h1 {
        text-align: center;
    }
    p.right {
        text-align: right;
    }
    p.main{
        text-align: justify;
    }
    <body>
        <p>链接到:<a href="https://www.baidu.com">百度</a></p>
    </body>

    4.装饰文字

    h1 {
        text-decoration: overline;
    }
    h2 {
        text-decoration: line-through;
    }
    h3 {
        text-decoration: underline;
    }
    <body>
        <h1>This is heading 1</h1>
        <h2>This is heading 2</h2>
        <h3>This is heading 3</h3>
    </body>

    5.控制文本中的字母

    p.u {
        text-transform: uppercase;
    }
    p.l {
        text-transform: lowercase;
    }
    p.c {
        text-transform: capitalize;
    }
    <body>
        <p class="u">this is some text.</p>
        <p class="l">this is some text.</p>
        <p class="c">this is some text.</p>
    </body>

    6.缩进文本

    p {
        text-indent: 50px;
    }
    <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>

    7.指定了字符之间的空间

    h1 {
        letter-spacing: 5px;
    }
    h2 {
        letter-spacing: -5px;
    }
    <body>
        <h1>This is heading 1</h1>
        <h2>This is heading 2</h2>
    </body>

    8.制定了行与行之间的空间

    p.small {
        line-height: 70%;
    }
    p.big {
        line-height: 200%;
    }
    <body>
       <p>
        这是一个标准行高的段落
        这是一个标准行高的段落
        大多数浏览器的默认行高约为110%至120%;
       </p>
       <P class="small">
        这是一个更小行高的段落。<br>
        这是一个更小行高的段落。<br>
        这是一个更小行高的段落。<br>
        这是一个更小行高的段落。
       </P>
       <P class="big">
        这是一个更大的行高的段落<br>
        这是一个更大的行高的段落<br>
        这是一个更大的行高的段落<br>
        这是一个更大的行高的段落
       </P>
    </body>

    9.设置元素的文本方向

    p.right {
         direction: rtl;
    }
    <body>
       <p>一些文本。默认书写方向</p>
       <p class="right">一些文本。从右到左的书写方向</p>
    </body>

    10.增加单词之间的空格

    p {
        word-spacing: 30px;
    }
    <body>
       <p>This is some text. This is some text.</p>
    </body>

    11.在一个元素内禁用文字换行

    p {
        white-space: nowrap; /* 不换行,在同一行显示!*/
    }
    <p>
        这是一些文本。这是一些文本。这是一些文本。这是一些文本。这是一些文本。
        这是一些文本。这是一些文本。这是一些文本。这是一些文本。这是一些文本。
        这是一些文本。这是一些文本。这是一些文本。这是一些文本。这是一些文本。
        这是一些文本。这是一些文本。这是一些文本。这是一些文本。这是一些文本。
        这是一些文本。这是一些文本。这是一些文本。这是一些文本。这是一些文本。
    </p>

    12.内部文字图像的垂直对齐

    img.top {
        vertical-align: text-top;
    }
    img.bottom {
        vertical-align: text-bottom;
    }
    <p>一个<img src="fun.jpg" wdith="250px" height="250px">默认对齐的图像。</p>
    <P>一个<img src="fun.jpg" class="top" wdith="250px" height="250px">text-top对齐的图像。</P>
    <P>一个<img src="fun.jpg" class="bottom" wdith="250px" height="250px">text-bottom对齐的图像。</P>
  • 相关阅读:
    react-echarts之折线图的显示
    Log4j2
    测试驱动开发Junit4
    JavaWeb基础: Cookie
    JavaWeb前端:Bootstrap基础
    JavaWeb前端:CSS
    JavaWeb前端:JQuery
    Android基础:Activity
    JavaWeb前端: JavaScript 简介
    JavaWeb前端:HTML5 简介
  • 原文地址:https://www.cnblogs.com/Tony98/p/10959222.html
Copyright © 2011-2022 走看看