非换行空白: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>

 

三 页面效果

转载于:https://www.cnblogs.com/sea-breeze/p/7285558.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值