Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Table th style width not working

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)

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?

like image 801
Riain McAtamney Avatar asked Mar 08 '11 12:03

Riain McAtamney


People also ask

How do I fix the width of a table in HTML?

To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width.

How do I force a table column width in HTML?

The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content. The specifications of width for the columns can be in pixels, or percentage.

How do I make a table width in HTML?

To manipulate the height or width of an entire table, place the size attribute (either "WIDTH=" or "HEIGHT=") within the <TABLE> code. To manipulate individual cells, place the size attribute within the code for that cell.


2 Answers

add

style="width: 100%;"

to the table

like image 198
Ahmed Khalaf Avatar answered Sep 20 '22 22:09

Ahmed Khalaf


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:

table#MyTable {
    width: x;    // x denotes overall size
}
like image 39
Mike B Avatar answered Sep 21 '22 22:09

Mike B