Old Tin Roof

A little bit of me, and everything else

Table cell min-height in Firefox

This week I came across a cou­ple of cross-browser css quirks that I’d never seen before (I guess because I’d never needed to imple­ment the ele­ments that caused them).  One that really stood out was the way that Fire­fox han­dles height val­ues on table cells dif­fer­ently to other browsers.

Most browsers use the nor­mal ‘con­tent box’ model to ren­der table cell con­tent (some slightly dif­fer­ently, and we have all had to deal with these box model quirks over the years), but Fire­fox uses the ‘bor­der box’ model.  You can see a group of exam­ples on Bruno Fassino’s site.

Sim­ply put, it changes the cal­cu­la­tion of the total ren­dered height of the table cell.  So set­ting a height of 130px and a bor­der of 5px means that the cell will be ren­dered as 140px in Fire­fox but 130px in every other browser. Bah!

The differences between the types of box models

It also ignores min-height val­ues, and treats height val­ues as min-height instead.

There is a CSS3 prop­erty called box-sizing, that allows you to spec­ify which model you want to use, but that changes the model for the width as well, which causes some more issues for width calculations.

Solu­tions

There are a cou­ple of solu­tions to get round this if you need a whole row of table cells to be a cer­tain height, but don’t want the has­sle of work­ing out widths (if you use the box-sizing css3).

1. Find a cell on the row that con­tains a fixed height ele­ment (e.g. a but­ton, or a title you know won’t change in length), and set top and bot­tom padding on that to get what you need.

2. Or, if you don’t have a fixed height ele­ment, then you can add a div around the con­tents of a table cell and set the min-height on that.

Sim­ple fix, but it took me a good bit of pok­ing around to find the rea­son for the quirk, I hope it helps some­one else.