非换行空白:non-breaking space

一 维基百科(英文版)词条

 

In word processing and digital typesetting, a non-breaking space (" ") (also called no-break space, non-breakable space (NBSP), hard space, or fixed space) is a space character that prevents an automatic line break at its position. In some formats, including HTML, it also prevents consecutive whitespace characters from collapsing into a single space.

 

In HTML, the common non-breaking space, which is the same width as the ordinary space character, is encoded as   or  . In Unicode, it is encoded as U+00A0.

 

1  不可中断空白连同前面一个、后面一个字符都在同一行,不会换行。

2 多个不可中断空白不会被视为一个字符

3 不可中断字符,在js中是\xA0,在html中是 

 

二 代码

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            *{
                margin:10px 0 0 0;
                padding:0;
            }
            .box{
                width:50px;
                height:50px;
                background:grey;
                font-size: 16px;
            }
        </style>
    </head>
    <body style="padding:0 50px;">
        <div class="box" id="box01">
            
        </div>
        <div class="box" id="box02">
            
        </div>
        <script>
            var str01 = '奥路\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0菲';
            document.getElementById('box01').innerHTML = str01;
            var str02 = '奥路&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;菲';
            document.getElementById('box02').innerHTML = str02;
        </script>
    </body>
</html>

 

三 页面效果

posted on 2017-08-04 15:49  沙滩海风  阅读(1420)  评论(0编辑  收藏  举报

导航