zoukankan      html  css  js  c++  java
  • css中的whitespace属性

    css中的white-space用来处理布局过程中元素内的空白符。

    white-sapce:

    normol: 默认值,空白会被浏览器忽略。

    <html>
        <head>
            <title>WhiteSpace</title>
            <style type = "text/css">
            span {
                white-space: normal;
                background: silver;
            }
            </style>
        </head>
        <body>
            <span>      
                    Some text。
                Some text。
            Some text。
            </span>
        </body>
    </html>

    运行结果
    元素标签<span>两端的空白符被忽略,但字符之间的空白保留。

    pre: 元素之间的空白符不被忽略。类似HTML标签中的<pre>

    <html>
        <head>
            <title>WhiteSpace</title>
            <style type = "text/css">
            span {
                white-space: normal;
                background: silver;
            }
            </style>
        </head>
        <body>
            <span>      
                    Some text。
                Some text。
            Some text。
            </span>
        </body>
    </html>

    运行结果(火狐):

    可以看到标签元素<span>之间的空白符被保留了。

    nowrap: 文本不会换行,文本会在一行之间继续,直到遇到<br />标签

    <html>
        <head>
            <title>WhiteSpace</title>
            <style type = "text/css">
            span {
                white-space: nowrap;
                background: silver;
            }
            div {
                width: 200px;
                background: gold;
                padding: 10px;
            }
            </style>
        </head>
        <body>
        <div>
            <span>      
                        Some text。
                Some text。
            Some text。
            Some text。
            Some text。
            Some text。
            Some text。
            Some text。
            </span>
        </div>
        </body>
    </html>

    运行结果:

    元素标签<span>之间的空格以及每行换行符被忽略。文本但是文本不会自动换行,一直溢出了div框。

    <html>
        <head>
            <title>WhiteSpace</title>
            <style type = "text/css">
            span {
                white-space: pre-wrap;
                background: silver;
            }
            </style>
        </head>
        <body>
            <span>      
                        Some text。
                Some text。
            Some text。
            </span>
        </body>
    </html>

    运行结果(火狐):

    元素标签<span>之间的空白被保留,换行符也被保留。

    pre-line: 合并空白符序,但是保留换行符。

    <html>
        <head>
            <title>WhiteSpace</title>
            <style type = "text/css">
            span {
                white-space: pre-line;
                background: silver;
            }
            </style>
        </head>
        <body>
            <span>      
                        Some text。
                Some text。
            Some text。
            </span>
        </body>
    </html>

    运行结果:

    元素标签<span>之间的空白符被忽略,但是换行符被保留。

    总之,white-space控制的就是表亲两端的空白符以及换行符的显示。

  • 相关阅读:
    第四周PLECS仿真
    三相异步电动机预习笔记
    第三周PLECS仿真
    《自动化技术中的进给电气传动》 1.3节及《控制系统设计指南》 第一,二章设计指南读书笔记
    第二周 PLECS仿真
    机电传动课程学习
    《实时控制软件设计》2017年度教学总结
    《实时控制软件设计》2017年教学内容
    《机电传动控制》(2017)综合作业
    《机电传动控制》(2017)第十一周作业
  • 原文地址:https://www.cnblogs.com/chaoguo1234/p/2941665.html
Copyright © 2011-2022 走看看