HTML自动换行不起作用?

时间:2012-07-31 09:20:14

标签: html css enter

我声明了widthmargins,但不知怎的,我的线条没有被自动换行包裹。

enter image description here

编辑: 我找到了原因。这是因为单词之间没有空格:

teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest teest 

6 个答案:

答案 0 :(得分:5)

text的元素应该有css声明:

div {
    display: block;
    width: 200px; /*based on how much width this div should have*/
}

如果不起作用,请尝试:

div { word-wrap: break-word } 

答案 1 :(得分:3)

逐一尝试,对某些情况一定有用:

p{
    display: block; /* or inline-block, at least its a block element */
    width: 100px; /* or width is certain by parent element */
    height: auto; /* height cannot be defined */
    word-break: break-all; /*  */
    word-wrap: break-word; /* if you want to cut the complete word */
    white-space: normal; /* be sure its not 'nowrap'! ! ! :/ */
}

答案 2 :(得分:1)

这将打印每行中的每个句子,而不是<br>

<p style="font-family:courier;white-space: pre;">
First Line
Second Line
Third Line
</p>

例如检查jsfiddle http://jsfiddle.net/muthupandiant/sgp8rjfs/

答案 3 :(得分:0)

    Try with `word-wrap` 

     #id
         { 
           word-wrap: break-word ;/*Allows unbreakable words to be broken*/
         } 

     #id
        { 
          word-wrap: normal ;/*Break words only at allowed break points*/
        } 

答案 4 :(得分:0)

真正的问题是:为什么地球上你想在你的情况下使用&amp; nbsp;

对于每个空间,这是6个字节而不是1个字节!

除了存储和文件大小的浪费之外,搜索引擎还会试图了解它。

我会选择退出无论出于什么原因你必须使用&amp; nbsp; 并选择加入朴素和简单的空间(“”),对于SEO和 - 更重要的是 - 少浪费空间。这样,您将实现相同的目标,但为网站访问者提供较小的下载量。

答案 5 :(得分:0)

另一种方法是:

white-space: pre-wrap; // preserve whitespace, the text is wrapped
overflow-wrap: break-word; // text is wrapped, line break on the end of a word