我想要一个可选的换行符,它始终不可见,可以与 word-wrap: break-word;
CSS 样式配合使用。
这里有一些细节。我的目标是在合理的地方分解长链接。这些字符是一个很好的起点:-
、.
、_
、/
、\
。这不是特定于 Rails 的问题,但我想分享一些我现在正在使用的代码:
module ApplicationHelper
def with_optional_line_breaks(text)
text.gsub(%r{([-._/\\])}, '\1­')
end
end
上面代码的问题是:当
生效时(在一个表中:word-wrap: break-word;
),­ ;
显示为 -
。我不想看到 -
;我想要一个不显示任何字符的换行符。
最佳答案
​
是称为零宽度空格 (ZWSP) 的 unicode 字符的 HTML 实体。
"In HTML pages, this space can be used as a potential line-break in long words as an alternative to the
<wbr>
tag."- Zero-width space - Wikipedia
<wbr>
标记也有效,如 Aaron's answer 所述.我想我更喜欢 HTML 实体而不是标签,因为实体看起来更简单:unicode 处理它,而不是网络浏览器。
关于html - 始终不可见的可选换行 HTML 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15841109/