当内容进入

时间:2018-01-16 03:34:40

标签: html css

我是编程新手。这是我尝试使用的代码:

<div style="width: 300px;">
    texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</div>

所以,问题是文本在300px之后不会中断。为什么以及如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

这也有效

div{
  word-wrap: break-word;
  width: 300px;
}
<div>
        texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
    </div>

答案 1 :(得分:0)

使用overflow-wrap: break-word来实现您的目标:

overflow-wrap CSS属性指定浏览器是否应在单词中插入换行符以防止文本溢出其内容框。

&#13;
&#13;
<div style="width: 300px; overflow-wrap: break-word">
    texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

请尝试以下代码来设置div的样式:

div{
    overflow-wrap: break-word; /* wrap/break lines that are longer the the container width */
    overflow: hidden; /* Not necessary but it will hide everything outside of the div box */
}

编程不是编码,HTML和&amp; CSS代码不是编程语言。下一次,你可以说你不熟悉前端开发。