javascript - 更改 html 字符串宽度

标签 javascript css html

我有 html,例如:

<div id='foo' style='background:transparent;color:white;width:120px'><p>test_text_test_text_test_text_test_text_test_text_test_text_test_text</p></div>

如果字符串宽度超过 120,我如何设置它的字符串 '\n'?对于前。可能是这样的:

<div id='foo' style='background:transparent;color:white;width:120px'><p>test_text_test_text\n_test_text_test_text\n_test_text_test_text\n_test_text</p></div>

我将非常感谢你的帮助

最佳答案

你应该使用 css 属性 - 自动换行

word-wrap:break-word;

示例:http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_word-wrap

关于javascript - 更改 html 字符串宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13141676/

相关文章:

javascript - live.js 与 prefixfree 结合使用时不会重新加载 css

html - 为什么 span padding 会导致渲染框与其父框重叠?

html - 意外的重叠部分

javascript - 是否有一个 jQuery 库可以将图像以类似拼贴的格式放入 div?

javascript - 针对 Laravel 后端的 Angular Auth

C# css 表(css 重新设计)

javascript - JS 递归过多

html - 多对象位置 HTML/CSS

javascript - mysqli 直接运行时有效,但通过 js-ajax 运行时无效

javascript 没有运行 jquery