如何使用 CSS 实现文本换行?
<td>gdfggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg</td>
如何让这样的文本在 CSS 中换行?
<td>gdfggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg</td>
How do I get text like this to wrap in CSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您输入“AAAAAAAAAAAAAAAAAAAAAARRRRRRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGGGGGG”
这将产生:
我从谷歌上的几个不同网站中获取了我的示例。我已经在 ff 5.0、IE 8.0 和 Chrome 10 上对此进行了测试。它适用于所有这些版本。
If you type "AAAAAAAAAAAAAAAAAAAAAARRRRRRRRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGGGGGG"
this will produce:
I have taken my example from a couple different websites on google. I have tested this on ff 5.0, IE 8.0, and Chrome 10. It works on all of them.
尝试这样做。适用于 IE8、FF3.6、Chrome
Try doing this. Works for IE8, FF3.6, Chrome
对于 text-wrap,浏览器支持相对较弱(正如您可能预计来自规范草案)。
您最好采取措施确保数据不包含长的非空白字符串。
With text-wrap, browser support is relatively weak (as you might expect from from a draft spec).
You are better off taking steps to ensure the data doesn't have long strings of non-white-space.
这在任何地方都适用。
This will work everywhere.
如果无法控制用户输入,更好的选择是建立 css 属性 overflow:hidden,因此如果字符串优于宽度,则不会使设计变形。
已编辑:
我喜欢答案:“word-wrap:break-word”,对于那些不支持它的浏览器,例如IE6或IE7,我会使用我的解决方案。
The better option if you cannot control user input, it is to establish the css property, overflow:hidden, so if the string is superior to the width, it will not deform the design.
Edited:
I like the answer: "word-wrap: break-word", and for those browsers that do not support it, for example, IE6 or IE7, I would use my solution.