【问题标题】:How can I convince IE to honor my explicit instructions to make a table column X pixels wide?如何说服 IE 遵守我的明确指示,使表格列宽 X 像素?
【发布时间】:2013-11-02 22:46:18
【问题描述】:

请考虑这个小而完整的 HTML 块:

<!DOCTYPE html >
<html>
<head>
    <title>Test</title>
    <style type="text/css">
    span {overflow:hidden; white-space:nowrap;  }
    td {overflow:hidden; text-overflow:ellipsis}
    </style>
</head>
<body>
    <table cellspacing="0"  >
        <tbody>
            <tr>
               <td nowrap="nowrap" style="max-width:30px; width:30px; white-space:nowrap; "><span>column 1</span></td>
               <td nowrap="nowrap" style="max-width:30px; width:30px; white-space:nowrap; "><span>column 2</span></td>
               <td nowrap="nowrap" style="max-width:30px; width:30px; white-space:nowrap; "><span>column 3</span></td> 
             </tr>
        </tbody>
    </table>
</body>
</html>

如果你在 Chrome 中渲染上面的内容,你会看到我正在寻找的效果。

但是在 IE8 或 9 中渲染它,宽度和/或最大宽度被忽略。

所以我的问题是如何让 IE 简单地让我明确指定单元格的宽度? (如果我也不必使用 max-width 来让 Chrome 正常运行,那也很好)。

顺便说一句,我尝试了各种 table-layout:fixed 组合以及使用 colgroup 和 cols 等各种组合,但我没有尝试说服 IE 去做我明确要求它明确做的事情。

【问题讨论】:

    标签: html css google-chrome internet-explorer html-table


    【解决方案1】:

    试试你的table 样式:

    table {table-layout: fixed; width :0px;}

    你可以放弃max-width:30px

    您确实提到过您使用了table-layout,但在此处说明width 可以解决问题

    【讨论】:

    • 它看起来不错,到目前为止我发现我可以放弃最大宽度,只需将表格宽度设置为 0px,所有浏览器都会生成相同的结果。
    • 我也不确定这个答案与我的有什么不同
    • 更改答案以反映您的评论@AnthonyWJones
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 2015-06-07
    相关资源
    最近更新 更多