HTML改变换行符触发器? [英] HTML change line break trigger?

查看:165
本文介绍了HTML改变换行符触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CSS / HTML中有什么方法可以改变什么字符导致文本中的换行符被允许?例如,如果我有包含文本fooooooo / barrrrrrrrrr的表数据,它将不会拆分成两行,但如果它包含fooooooo barrrrrrrrrr,它会。



解决方案

在CSS / HTML中是不可能的更改导致,允许或防止文本中的换行符的字符集。然而,可以对于每个字符的发生影响这样的事情。也就是说,你不能一般地说linebreak after'/'is allowed,但是你可以在特定的/之后插入一些标记或内容,以允许在那里换行。



请注意,浏览器具有不同的换行行为。例如,Opera将斜杠/视为允许换行符。行为还可以取决于上下文。请参阅浏览器中的换行符页面。



对于任何知道实用方法并且不太担心标准化程序不愿意接受它的人来说,以前简单的:< wbr> 标签。它仍然是简单的实际方式,例如。 fooooooo /< wbr> barrrrrrrr ,但它不是最多的跨浏览器方式了。更新的方式,零宽度空间U + 200B,可以写成&#x200b; 在HTML中,在现代浏览器,但在一些旧版本的IE,它会创建一个混乱(一个小矩形显示在这个控制字符出现的位置)。



如果你愿意使用有点冗长的代码,方法。您将使用< wbr> 和具有空内容但具有零宽度空间的内联元素作为生成内容。这避免了IE 6上的问题,因为它不支持CSS中的生成内容(但是识别< wbr> 标记)。范例:

  fooooooo /< wbr>< a class = wbr>< / a> barrrrrrrr 



使用CSS代码

  .wbr:after {content:\00200B; } 

测试和演示: jsfiddle


Is there any way in CSS/HTML to change what characters cause linebreaks in text to be allowed? For example if I have table data containing the text "fooooooo/barrrrrrrrr" it won't get split on two lines, but if it contains "fooooooo barrrrrrrrr" it will.

Is there a way to add punctuation characters to what can trigger line break?

解决方案

It is not possible in CSS/HTML to change the set of characters that cause, allow, or prevent linebreaks in text. However, it is possible to affect such things per each occurrence of a character. That is, you cannot say in general "linebreak after ‘/’ is allowed", but you can inject some markup or content after a particular occurrence of "/" to allow a line break there.

Note that browsers have different line breaking behavior. For example, Opera treats the slash "/" as allowing a line break after it. The behavior may also depend on the context. See my page on line breaking in browsers.

Thinks used to be simple, to anyone who knew the practical method and wasn’t too worried about the reluctance of standardizers to accept it: the <wbr> tag. It is still the simple practical way, e.g. fooooooo/<wbr>barrrrrrrrr, but it isn’t the most cross-browser way any more. The newer way, the zero-width space U+200B, which can be written as &#x200b; in HTML, works well on modern browsers, but on some old versions of IE, it creates a mess (a small rectangle is displayed where this control character appears).

If you are willing to use somewhat verbose code, you can combine the two ways. You would use both <wbr> and an inline element with empty content but with zero-width space as generated content. This avoids the problem on IE 6, as it does not support generated content in CSS (but recognizes the <wbr> markup). Example:

fooooooo/<wbr><a class=wbr></a>barrrrrrrrr

with CSS code

.wbr:after { content: "\00200B"; }

Test and demo: jsfiddle.

这篇关于HTML改变换行符触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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