Riain McAtamney
Riain McAtamney

Reputation: 6432

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?

Upvotes: 9

Views: 50948

Answers (4)

Mike B
Mike B

Reputation: 12797

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
}

Upvotes: 2

anothershrubery
anothershrubery

Reputation: 21023

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.

Upvotes: 0

Ahmed Khalaf
Ahmed Khalaf

Reputation: 1220

add

style="width: 100%;"

to the table

Upvotes: 5

keithics
keithics

Reputation: 8758

try adding a 100% width to the table..

Upvotes: 0

Related Questions