如何在html中定义条件换行符? [英] How to define conditional line break in html?
问题描述
如有必要,我希望这个字符串在 *
处中断(没有更多的地方可以写了).
I would like this string to break at *
if necessary (there is no more place to write).
7 380 Ft,*159 Ft termékdíjjal
喜欢
7 380 000 Ft,
159 125 Ft termékdíjjal
如何在 html 中实现这一点?
How to achieve this in html?
产生错误"的中断,例如:
produces "wrong" breaking, like:
7 380 000 Ft, 159 125
Ft termékdíjjal
推荐答案
有两种方法可以指定条件(允许)换行符:<wbr>
标签,HTML5 中正在标准化,零宽度空格字符 (U+200B,​
).两者都在现代浏览器中运行良好,但如果你想覆盖旧浏览器,有很多棘手的 问题.
There are two ways to specify a conditional (allowed) line break: the <wbr>
tag, which is being standardized in HTML5, and the zero width space character (U+200B, ​
). Both work well in modern browsers, but if you wish to cover old browsers, there are many tricky issues.
另一方面,任何空格通常都被视为允许换行.因此,可能真正需要的只是在必须不出现换行符的情况下使用不间断空格而不是空格.
On the other hand, any space is normally treated as allowing a line break. So what might really need is just the use no-break spaces instead of spaces in situations where a line break must not appear.
示例:
7 380 000 Ft, 159 125 Ft termékdíjjal
如果您使用不间断空格 U+00A0 本身而不是
参考,则源代码更具可读性.输入方法因程序而异.
The source is more readable if you use the no-break space U+00A0 itself instead of the
reference. The method of typing it varies by program.
这篇关于如何在html中定义条件换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!