Firefox issue with display:absolute in a table cell

后端 未结 2 909
广开言路
广开言路 2020-12-10 05:53

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

相关标签:
2条回答
  • 2020-12-10 06:13

    Did you try to set the position of the TD explicitly to relative?

    This should reset the positioning. Actually, it is correct behavior what you are getting, and should not be only related to TD, but you know, browsers are fun.

    For details on why you need to explicitly set it, check:
    http://css-tricks.com/791-absolute-positioning-inside-relative-positioning/

    ..

    Update:

    This answer suggested trying an option. It's written earlier than accepted answer, and is not deleted just for archival reasons and as it is another related possibility for those coming here from search engines for slightly similar but not same problem. I appreciate your understanding.

    0 讨论(0)
  • 2020-12-10 06:18

    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.

    0 讨论(0)
提交回复
热议问题