Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table-layout:fixed rendering differences in Safari

Basically the problem I have is that in Safari/Chrome it is changing the width of my columns even though I have specified a) a width on the table, b) table-layout:fixed, and c) specific widths on my first row that when added with the padding and border values add up to the width of the table specified. In IE7 and Firefox 3 the table is rendered the same. But in Safari/Chrome it decides to make the second column bigger by taking space from the other columns.

Any ideas? I have a very simple sample page that you can look at, as well as an image showing how the table is rendered in all three browsers for comparison.

like image 364
patmortech Avatar asked May 31 '10 12:05

patmortech


3 Answers

In buggy webkits, table-layout: fixed also gives your table cells box-sizing: border-box. One alternative to browser detection is explicitly set box-sizing: border-box to get consistent behavior across browsers, then adjust your widths and heights accordingly (widths and heights must be increased to include padding and borders).

#my-table td {
  box-sizing: border-box;
} 
like image 151
Muir Avatar answered Oct 15 '22 15:10

Muir


I was able to get around this problem by removing the padding from the <th> with the fixed width. You can then safely add padding to the <td>

like image 4
John Magnolia Avatar answered Oct 15 '22 16:10

John Magnolia


After looking around, I think that this is caused by the following webkit bugs: 13339 and 18565. Basically a problem with how it uses the border and padding values in calculating the final width of the columns.

I ended up doing some browser-sniffing and setting some different css values based on that for webkit browsers so that the final rendering was the same as FF and IE.

like image 1
patmortech Avatar answered Oct 15 '22 15:10

patmortech