html emsp兼容性,HTML emsp entity exact behavior

本文探讨了 HTML 中 emsp 实体的行为特性,包括其在不同情况下的换行与缩进表现。通过实验验证了 emsp 实体与普通空格在换行规则上的差异,并总结了多个 emsp 实体相邻时的显示效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am having trouble finding an exact reference of the behavior of the HTML emsp entity. I have looked at W3.org, MDN, W3schools, and here, but I have not yet found a description that describes its breaking or wrapping behavior in HTML that does not have any special styling applied.

The code below shows an experiment I resorted to, but I am still a bit confused about when it will and will not wrap. Is there a good reference?

body {

font-size: 20px; font-family: Courier, fixed;

}

Following is some text with some embedded emsp entities.
Here is one mid-word: sam ple.
And here is one on each side of a dash: lock - step.
Then, how about one after a period?
Right after the next period is one and then a normal space.  How about the standard space and then the emsp?
That sequence follows this sample sentence.  (Note that since the regular space came first, this can cause this text after it to become indented, whereas the emsp-then-regular space occurrence just before will never do that, I think.) As long as I'm looking at them after the end of a sentence, we should try putting just one emsp after a sentence instead of the regular space caracter.
I thought that would stick the two sentences together, but it does not do so here. Indeed, this is consistent with its behavior mid-word. Okay, how about multiple occurrences of it?
There are 3 in the brackets here: [   ] and so on. I played with that last one a bit and I cannot get it to break after the 3 emsps. Here, they seem to keep their width (they are not combined into one) and they are not breakable, not even either before the first or after the last one. So, I seem to only be able to get the "[" and never the "]" as the first character on a new line.
Okay, more extremely, trying brackets around 5 emsp chars, a word, and 5 more emsp chars: [     word     ] .
There we seem able to break before "word", but still never before "]". What's going on there?

From the examples above, I think the mystery around emsp characters is mostly resolved for me.

Consider the standard behavior for a regular space character. Here, first remember that multiple occurrences of regular whitespace characters are all compressed as if they were a single regular space character. Then, of course, the regular space character takes a certain width, and lines are never broken just before the regular space, only after it. And the space normally allocated for a regular space character does not need to be rendered at the right edge of a box.

Similarly, text can break after an emsp character, but will not do so before. It is wider than a regular space character, but mostly behaves like it. Where it differs is if you have multiple emsp entities right next to each other. In that case, no break will occur before, within, or after the group (unless there is whitespace before or after it, in which case the whitespace is the location of the break). But if a set of multiple emsp characters are placed directly between two non-white characters (as in the bracket example above) then they are not compressed and no breaking occurs. That's all I'm thinking of at the moment ...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值