Html 如何使div断线?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17049331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:19:08  来源:igfitidea点击:

How to make div break line?

htmlcss

提问by Luis Parker

I have the following code:

我有以下代码:

.thing {
  width: 90%;
  height: 400px;
  border: 10px solid #000;
}
<div class="thing">
  aaaaaaaaaaaa
</div>

The problem is that when I add to much content, the text goes out of the div!

问题是当我添加很多内容时,文本会从 div 中消失!

How to fix this using only CSS?

如何仅使用 CSS 解决此问题?

回答by Bhushan Kawadkar

.thing {
width: 90%;
height: 400px;
padding: 10px solid #000;
word-break:break-all;
}

use word-break

使用断字

回答by fahd4007

this happen coze you are not adding space

这是因为你没有增加空间

just add a space some where between 'aa' like this >'aaaaaa aaaaaa' there is not word with 12 character

只需在 'aa' 之间添加一个空格,就像这样 >'aaaaaa aaaaaa' 没有12 个字符的单词

but if you need this long word then use

但如果你需要这个长词然后使用

word-break:break-all;