简体   繁体   中英

Text content of div set by JS wont break to new line

i have some div created with JS and mydiv.textContent="blahblahblahblahblahblah"; despite the fact mydiv have width set to 100px, string of text assigned to div keeps on going in one line and wont drop to other text. i am confused

在您的CSS中使用

word-wrap: break-word;

If you want to make a string breakable into two lines and it contains no spaces, you need to insert suitable control characters or HTML tags that allow acceptable breaks, or maybe use automatic hyphenation. So this really depends on the kind of content you have; see my page on word breaks in HTML.

If the content is literally "blahblahblahblahblahblah" as a JavaScript string, make it "blah\\xadblah\\xadblah\\xadblah\\xadblah\\xadblah" . The notation \\xad stands for U+00AD SOFT HYPHEN, which is treated as an invisible hyphenation hint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM