我不建议使用奇怪的CSS属性,即使在Chrome和Firefox中也没有.最好的跨浏览器解决方案是在文档加载时在Javascript中处理此问题.这是如何做到这一点的草图:
$(function() {
$(".title").each(function(i,title) {
var width = 0;
var originalHeight = $(title).height();
var spacer = $('<div style="float:right;height:1px;"/>').prependTo(title);
while (originalHeight == $(title).height()) {
spacer.width( ++width );
}
spacer.width( --width );
});
});
Run Code Online (Sandbox Code Playgroud)
工作JSFiddle在这里:http://jsfiddle.net/zephod/hfuu3m49/1/
好吧,如果这取决于文本,那么您可以尝试诸如单词替换器之类的东西。例如
var words = "This is what I want to achieve";
var newWords.replace("what", "what <br />"); // note the line break
document.write(newWords);
Run Code Online (Sandbox Code Playgroud)
这是给您的小提琴:http ://jsfiddle.net/afzaal_ahmad_zeeshan/Ume85/
否则,我认为您不能根据一行中的字符数来换行。