css - 嵌套表格中的长字换行

标签 css html-table

我想把一个长词换行。我看过这篇文章:How to prevent long words from breaking my div?

在像这样的简单情况下效果很好:

.wrapWords
{
    white-space: pre;           /* CSS 2.0 */
    white-space: pre-wrap;      /* CSS 2.1 */
    white-space: pre-line;      /* CSS 3.0 */
    white-space: -pre-wrap;     /* Opera 4-6 */
    white-space: -o-pre-wrap;   /* Opera 7 */
    white-space: -moz-pre-wrap; /* Mozilla */
    white-space: -hp-pre-wrap;  /* HP Printers */
    word-wrap: break-word;      /* IE 5+ */

}

<!-- This wraps correctly -->
<div style="width:145px;">
    <div class="wrapWords" style="width:100%;">
        <a href="#">AAAAAAAAAAAAAAAAAA</a>
    </div>
<div>

但我的案例有两个这样的嵌套表:

<!-- This doesn't work -->
<table style="width:100%;">
    <tr>
        <td style="width:145px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <div class="wrapWords" style="width:100%;">
                            <a href="#">BBBBBBBBBBBBBBBBBB</a>
                        </div>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
        </td>
        <td>
        </td>
    </tr>
</table>

您可以在此处测试此代码 http://jsfiddle.net/ZmnQ6/4/

最佳答案

table 默认采用 table-layout: auto;,因此随着内容的增加,宽度也会增加,因此您需要将 table-layout 设置为 fixed。

table{
    table-layout: fixed;
}

demo

关于css - 嵌套表格中的长字换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19537209/

相关文章:

php - 页面无法在 IE8 中正确呈现

css - 定位/间距/定心表数据

javascript - 如何解决未捕获的类型错误 : Cannot read property 'length' of undefined of my Global varible?

javascript - 如何为表格中的每一列设置背景颜色?

php - 使用 wordpress $wpdb 在 <table> 中显示数据库中的数据

css - GWT TabLayoutPanel 使用 cssresources

html - 如何创建粘性页脚 - 另一种粘性?

jquery - 使用 jQuery 删除 css 属性

javascript - 如何仅选择 <thead> 和 <tbody> 内容复制到剪贴板?

html - 无法使用 CSS 控制表格宽度