Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Width of Table cell based on colgroup not working

Tags:

Setting width for table cell using colgroup not works in IE9

<table id="Grid1_Table" class="Table">
    <colgroup>
        <col style="width:20px">
        <col style="width:20px">
        <col style="width:180px">
        <col style="width:200px">
    </colgroup>
    <tbody>
        <tr>
            <td class="RowHeader"><div>&nbsp;</div></td>
            <td class="RecordPlusCollapse"><div>&nbsp;</div></td>
            <td colspan="2" class="GroupCaption">Order ID: 0 - 1 Items</td>
        </tr>
    </tbody>
</table>
.RowHeader
{
    background-color : black;
}
.GroupCaption
{ 
    background-color : #868981;
}
.RecordPlusCollapse
{
    background-color : red;
}
.Table{
    width: 100%;
}

First 2 <td> width is not as colgroup in IE9. Not sure why width differs.

http://jsfiddle.net/KgfsM/3/

like image 423
Sridhar Narasimhan Avatar asked Dec 20 '12 19:12

Sridhar Narasimhan


People also ask

How fix TD table width?

Using width attribute: The <td> tag has width attribute to control the width of a particular column. By assigning a numeric value to this attribute between 0 to 100 in terms of percentage(or you can use pixel format). We can restrict the column width up to that much percentage of the table's total width.

Is Colgroup deprecated?

However, most of the HTML colgroup attributes have been deprecated, and they are shown in the following list: align – used to specify the horizontal alignment of each column cell. bgcolor – used to alter the background color of the cells.

How do I keep my table width fixed 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 you give equal width to all TD tables?

Using table-layout: fixed as a property for table and width: calc(100%/3); for td (assuming there are 3 td 's). With these two properties set, the table cells will be equal in size.


1 Answers

You are giving the table 100% width and then go for fixed width cols. Where should the browser take the missing width from? It simply stretches the table cells.

Look at this example, works in every major browser, starting with IE 5(!) :) http://jsfiddle.net/Volker_E/ppRgV/1/

Changes were stripping width: 100%; from table and adding table-layout: fixed;

.Table {
   table-layout: fixed;
}
like image 184
Volker E. Avatar answered Oct 12 '22 01:10

Volker E.