W3School-CSS 文本实例

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>

846157-20151204160819830-123240828.png


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>

846157-20151204224041799-907029134.png


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>

846157-20151204224910143-653993078.png


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>

846157-20151205145406611-348719484.gif


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>

846157-20151205150644080-1613678367.gif


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>

846157-20151205150644080-1613678367.gif


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>

846157-20151205221425752-669317157.gif


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>

846157-20151206101518846-676328036.png


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>

846157-20151206115812314-1878805175.png


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>

846157-20151206130951924-204943228.png


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>

846157-20151206145214955-305264909.png


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>

846157-20151206152138111-1382947636.png


CSS文本实例总结:

846157-20151206201916003-1100837719.png

转载于:https://www.cnblogs.com/hoey/p/5019592.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值