HTML Table th 样式宽度不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5232172/
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 07:11:33  来源:igfitidea点击:

HTML Table th style width not working

htmlhtml-tablewidth

提问by Riain McAtamney

I have a table like so:

我有一张像这样的桌子:

<table id="MyTable" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th style="width: 30%;">
                <asp:Literal ID="LitDescriptionTitle" runat="server" />
            </th>
            <th style="width: 30%;">
                <asp:Literal ID="LitDescription2Title" runat="server" />
            </th>
            <th style="width: 30%;">
                <asp:Literal ID="LitAddressTitle" runat="server" />
            </th>
            <th style="width: 10%;">
                &nbsp;
            </th>
        </tr>
    </thead>
<tbody>

Now the column widths are set correctly to the percentages in IE, but not in firefox. (Probably FF doing something correctly)

现在列宽已正确设置为 IE 中的百分比,但在 Firefox 中却没有。(可能是 FF 正确地做某事)

Is there something I can do to get the widths of the columns to be fixed to the above percentages in both IE and FF?

我可以做些什么来使 IE 和 FF 中的列的宽度固定为上述百分比?

采纳答案by Ahmed Khalaf

add

添加

style="width: 100%;"

样式=“宽度:100%;”

to the table

到桌子上

回答by Mike B

You've set the percentages to be percentages, but percentages of what?

您已将百分比设置为百分比,但百分比是什么?

Try setting the width of the table itself, either using style="width: x"or in the CSS with:

尝试使用style="width: x"或在 CSS 中设置表格本身的宽度:

table#MyTable {
    width: x;    // x denotes overall size
}

回答by anothershrubery

I can't replicate the percentages being correctly set in IE, FF or Chrome. To get the percentages set correctly you must set a width to the outlying table. Whether that is an absolute or relative value is up to you. But remember not to use inline styles.

我无法复制在 IE、FF 或 Chrome 中正确设置的百分比。要正确设置百分比,您必须为外围表格设置宽度。这是绝对值还是相对值取决于您。但记住不要使用内联样式。

回答by keithics

try adding a 100% width to the table..

尝试向表格添加 100% 宽度。