CSS IE8 忽略 td 宽度,适用于 IE7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3306861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:26:48  来源:igfitidea点击:

IE8 ignores td width, works on IE7

cssinternet-explorer-8html-tablewidth

提问by Bill

There is a table looking like this:

有一张桌子看起来像这样:

<table width="100%">
<tr id="header">
 <td colspan="2"></td>
</tr>
<tr id="center">
 <td id="left" style="width: 201px"></td>
 <td id="mainpage" style="width: 100%"></td>
</tr>
</table>

In every browser (including IE7) apart from IE8 the "left" td is fine. In IE8 it exceeds the width according to the mainpage's content.

在除 IE8 之外的每个浏览器(包括 IE7)中,“左”td 都很好。在 IE8 中,它会根据主页的内容超出宽度。

I'd post some screenshots but it's my first post here.

我会发布一些屏幕截图,但这是我在这里的第一篇文章。

Any ideas whatsoever?

有什么想法吗?

回答by Razor

That width: 100%on the second column doesn't look right - if you're trying to make the second column expand to the rest of the available space, you shouldn't need that at all, so you can remove it. Also, add this to your table:

width: 100%第二列看起来不正确的-如果你想使第二列扩展到可用空间的其余部分,你不应该需要,在所有的,所以你可以将其删除。另外,将此添加到您的表中:

table-layout: fixed;

to make sure that the widths are obeyed.

以确保遵守宽度。

complete code:

完整代码:

<table style="width: 100%; table-layout: fixed;">
<colgroup>
    <col style="width: 201px">
</colgroup>
<tr id="header">
    <td colspan="2"></td>
</tr>
<tr id="center">
    <td id="left"></td>
    <td id="mainpage"></td>
</tr>
</table>

回答by Sarfraz

Are you sure it should be 100%

你确定应该是 100%

<table width="100%">

The table will be as large as its parent element. May be you should set a fixed width for the table:

表格将与其父元素一样大。可能你应该为表格设置一个固定的宽度:

<table width="600">

回答by Boris Delormas

If you define a width to your table and to your first you don't need to define it for your second .

如果您为表格和第一个定义宽度,则不需要为第二个定义它。

I guess the second gets 100% from container which is the table.

我想第二个从容器中获得 100%,即表。

回答by Bill

Well, problem somewhat fixed by adding an empty table with a fixed width inside the mainpage .

好吧,通过在 mainpage 内添加一个固定宽度的空表来解决问题。

That way I'm actually setting a min-width to the regardless IE's ignoring attitude. Thanks for all the answers.

这样我实际上设置了一个最小宽度,不管 IE 的无视态度。感谢所有的答案。