[英]Word-wrap in a table-cell
I want a table that uses all the screen if necessary but does break words if they get too long. 我想要一个必要时使用所有屏幕的表,但是如果它们太长的话会断字。
I tried: 我试过了:
<table width=100%>
<tr><td class=breaklines> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
</td></tr>
</table>
.breaklines
{
word-wrap: break-word;
}
It does not work, the words in the table-cell are never broken. 这是行不通的,表格单元格中的单词永远不会中断。
So how to break the words in a table-cell? 那么如何在表单元格中打断单词呢?
Fiddle: 小提琴:
https://jsfiddle.net/9u0pj3hn/ https://jsfiddle.net/9u0pj3hn/
There's a interesting trick that works for table cells, and it works for text-overflow too. 有一个有趣的技巧适用于表格单元,也适用于文本溢出。 It's including max-width like this:
它包括这样的最大宽度:
See it working: https://jsfiddle.net/9u0pj3hn/1/ 看到它正常工作: https : //jsfiddle.net/9u0pj3hn/1/
.breaklines
{
word-wrap: break-word;
max-width:0;
}
Hi You can also used this solution. 您好,您也可以使用此解决方案。
table{ width: 100%; word-wrap:break-word; table-layout: fixed; }
<table width=100%> <tr><td class=breaklines> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA </td></tr> </table>
You need to change table-layout
to fixed
. 您需要将
table-layout
更改为fixed
。
http://www.w3schools.com/cssref/pr_tab_table-layout.asp
http://www.w3schools.com/cssref/pr_tab_table-layout.asp
table.breaklines { width: 100%; table-layout:fixed; } .breaklines { word-wrap: break-word; }
<table class="breaklines"> <tr><td class="breaklines"> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA </td></tr> </table>
You can achieve the same result by using break-all
. 您可以通过使用
break-all
获得相同的结果。 Hence if you write you code 因此,如果您编写代码
<td style="word-break:break-all;">AAAAAAAAAAAAAAAAAAAA</td>
or 要么
<span style="word-break:break-all;">AAAAAAAAAAAAAAAAAAAAA</span>
Then it will work. 然后它将起作用。 See it working: http://jsfiddle.net/johannesMt/9kmmqphx/
看到它正常工作: http : //jsfiddle.net/johannesMt/9kmmqphx/
U need to set the width of the <td>
in order let HTML know where to break the word. 您需要设置
<td>
的宽度,以使HTML知道在何处打断该单词。 For example: 例如:
<td style="width:50px;">AAAAAA</td>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.