I have an external <div> that is relatively positioned and has a specific size. Inside it, I have a <table> object that is absolutely positioned and top , left , right and bottom set to zero. I expected the table to be expanded to comply with the restrictions of top / left / right / bottom, however this is not what happens. Instead, table sizes are calculated based on its contents.
If I use the internal <div> instead of <table> , then it works as I expected. On the other hand, if I put display: table; into the internal <div> , then it behaves exactly like a table.
My question is: why is this happening? Where in the specifications is this behavior defined? Or is this a bug in browsers (very unlikely)?
I checked the CSS 2.1 specification , I read sections 9.7. Relations between "display", "position" and "swimming" , 10.3.7 Absolutely positioned, not replaced elements , 17 tables . I also checked the CSS attribute on the Mozilla Developer Network . I also searched on StackOverflow. And yet, I cannot find an explanation of why tables behave this way.
See the demo version: http://jsfiddle.net/LgCDE/2/ I can reproduce the results on both Chrome 27 and Firefox 20.0.
HTML:
<div class="box"> <table class="table"> <tr> <td>Hey!</td> </tr> </table> </div> <div class="box"> <div class="table">Hey!</div> </div> <div class="box"> <div class="table" style="display: table;">Hey!</div> </div>
CSS
div.box { position:relative; border: 2px dashed red; background: #800; width: 100px; height: 50px; } .table { position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: auto; height: auto; margin: 0; border: 3px double blue; background: #CCF; table-layout: fixed; border-collapse: collapse; }

Denilson sΓ‘ maia
source share