I have found an issue when using absolutely positioned content within a td
element. The td
element is not being recognised as a positioned element so the content is being positioned relative to the body
. This issue is only in FireFox and the expected layout is visible in other browsers - jsfiddle.
Doing a little digging around it seems that the issue is related to FireFox using display:table-cell
as the default display type for table cells. I can resolve the issue by changing the display to block
or by adding a div
container to act as a positioned container to the content.
Is there any reason to avoid changing the display type of the cell to block
? I would prefer to use this method rather than adding additional elements to correct an issue in one browser.
This is not the same issue as described in either div style absolute in a table cell or Why "display: table-cell" is broken when "position: absolute".
If you set the display of the cell to block
it will get wrapped in an anonymous table cell. The resulting CSS box tree is the same as if you created a <div>
inside the cell and set all the cell's styles and attributes on that block.
This might be OK for many purposes. It'll break if the cell has a rowspan or colspan (because those don't mean anything on blocks) or if the cell has border styles that you expect to take part in border collapsing or if you have two such cells next to each other (because then the two blocks will be wrapped in a single table cell, not in two separate table cells). There are probably other situations where the behavior will be unexpected. But if you have enough control over the styles and content and aren't doing too much styling of the cell, this will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With