问题描述
如何显示长字符串,网站地址,字词或一组符号,并带有自动换行符以保持div宽度?我想是一个wordwrap的种类。通常添加一个空格工作,但是有一个CSS解决方案,如word-wrap?
How can you display a long string, website address, word or set of symbols with automatic line breaks to keep a div width? I guess a wordwrap of sorts. Usually adding a space works but is there a CSS solution such as word-wrap?
例如它(非常nastily)重叠div,强制水平滚动等$ b $我可以添加到上面的字符串,以适应它在一个div或浏览器窗口中的几行内吗?
For example it (very nastily) overlaps divs, forces horizontal scrolling etc.wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
推荐答案
此问题已在此之前提出过:
This question has been asked here before:
- Who has solved the long-word-breaks-my-div problem? (hint: not stackoverflow)
- word wrap in css / js
- CSS: how can I force a long string (without any blank) to be wrapped in XUL and/or HTML
- CSS overflow with long URL
详细说明:
overflow:scroll;
强制元素显示滚动条和 overflow:hidden;
有 text-overflow:ellipsis;
和 word-wrap:break-word;
code> break-word 是在CSS3草案,但是,这将是这个5年后的解决方案)。
As far as CSS solutions go you have: overflow: scroll;
to force the element to show scrollbars and overflow:hidden;
to just cut off any extra text. There is text-overflow:ellipsis;
and word-wrap: break-word;
but they are IE only (break-word
is in the CSS3 draft, however, so it will be the solution to this 5 years from now).
底线是,如果你非常重要的是阻止这种情况发生包装文本到下一行,唯一合理的解决方案是注入& shy;
(soft hyphen),(word break tag),或(零宽度空间,效果与& shy;
减号)相同。如果你不介意Javascript,但是,有一个看起来很漂亮的固体。
Bottom line is that if it is very important for you to stop this from happening with wrapping the text over to the next line the only reasonable solution is to inject ­
(soft hyphen), <wbr>
(word break tag), or ​
(zero-width space, same effect as ­
minus hyphen) in your string server side. If you don't mind Javascript, however, there is the hyphenator which seems to be pretty solid.
这篇关于wordwrap一个很长的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!