word-wrap break-word在这个例子中不起作用

b10*_*ard 55 html css

我无法使用自动换行来处理这个例子......

<html>
<head></head>
<body>

<table style="table-layout:fixed;">
<tr>
<td style="word-wrap: break-word; width:100px;">ThisStringWillNotWrapThisStringWillNotWrapThisStringWillNotWrapThisStringWillNotWrapThisStringWillNotWrapThisStringWillNotWrapThisStringWillNotWrapThisStringWillNotWrapThisStringWillNotWrap</td>
</tr>
</table>

</body></html>
Run Code Online (Sandbox Code Playgroud)

我记得读过必须指定布局(我做过),但除此之外我不知道要做什么才能让它工作.我真的希望这能在Firefox中运行.谢谢.

编辑:Chrome 19和Firefox 12失败,它适用于IE8.我试过doctype strict和transitional,都没有用.

Ste*_*cil 90

Mozilla Firefox解决方案

加:

display: inline-block;
Run Code Online (Sandbox Code Playgroud)

你的风格td.

基于Webkit的浏览器(谷歌浏览器,Safari,...)解决方案

加:

display: inline-block;
word-break: break-word;
Run Code Online (Sandbox Code Playgroud)

你的风格td.

注意:请 注意,就目前而言,break-word它不是webkit标准规范的一部分; 因此,您可能有兴趣使用break-all相反.这种替代价值提供了无疑是极为激烈的解决方案; 但是,它符合标准.

Opera解决方案

加:

display: inline-block;
word-break: break-word;
Run Code Online (Sandbox Code Playgroud)

你的风格td.

上一段以类似的方式适用于Opera.

  • 这与word-wrap不同:break-word; 使用分词:break-all"可以在任何字符之间插入单词分隔符" (7认同)
  • 在 Chrome 中为我工作,“word-break:break-word”有效,而“word-wrap:break-word”则无效。 (2认同)

Sun*_*S.M 38

使用适用于所有浏览器的代码(取自css-tricks)

overflow-wrap: break-word;
word-wrap: break-word;

-ms-word-break: break-all;
/* This is the dangerous one in WebKit, as it breaks things wherever */
word-break: break-all;
/* Instead use this non-standard one: */
word-break: break-word;

/* Adds a hyphen where the word breaks, if supported (No Blink) */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
Run Code Online (Sandbox Code Playgroud)


Far*_*eed 36

工作休息与inline-block.

确保您指定width并注意父节点中是否有任何覆盖属性。确保没有white-space: nowrap.

看到这个代码笔

<html>

<head>
</head>

<body>
  <style scoped>
    .parent {
      width: 100vw;
    }

    p {
      border: 1px dashed black;
      padding: 1em;
      font-size: calc(0.6vw + 0.6em);
      direction: ltr;
      width: 30vw;
      margin:auto;
      text-align:justify;
      word-break: break-word;
      white-space: pre-line;
      overflow-wrap: break-word;
      -ms-word-break: break-word;
      word-break: break-word;
      -ms-hyphens: auto;
      -moz-hyphens: auto;
      -webkit-hyphens: auto;
      hyphens: auto;
    }


    }
  </style>
  <div class="parent">

    <p>
      Note: Mind that, as for now, break-word is not part of the standard specification for webkit; therefore, you might be interested in employing the break-all instead. This alternative value provides a undoubtedly drastic solution; however, it conforms to
      the standard.

    </p>

  </div>

</body>

</html>
Run Code Online (Sandbox Code Playgroud)

  • 感谢上帝!空白:nowrap 是我的解决方案。怎么有这么多属性可以做同样的事情? (4认同)

Rub*_*ain 8

max-width: 100px;
white-space: break-spaces;
Run Code Online (Sandbox Code Playgroud)


D.D*_*glo 6

这种属性的组合对我有帮助:

display: inline-block;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: normal;
line-break: strict;
hyphens: none;
-webkit-hyphens: none;
-moz-hyphens: none;
Run Code Online (Sandbox Code Playgroud)