如何在html中定义条件换行符? [英] How to define conditional line break in html?

查看:34
本文介绍了如何在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,&#x200b;).两者都在现代浏览器中运行良好,但如果你想覆盖旧浏览器,有很多棘手的 问题.

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, &#x200b;). 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&nbsp;380&nbsp;000&nbsp;Ft, 159&nbsp;125&nbsp;Ft termékdíjjal

如果您使用不间断空格 U+00A0 本身而不是 &nbsp; 参考,则源代码更具可读性.输入方法因程序而异.

The source is more readable if you use the no-break space U+00A0 itself instead of the &nbsp; reference. The method of typing it varies by program.

这篇关于如何在html中定义条件换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆