Can someone explain why the two table layouts below do not match (in particular, why the second "table-cell" div is not stretched to take the rest of the width of the parent div "table", since it is in a real table)?
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head></head> <body> <div style="width: 100%; border: 1px solid black;"> <div style="display: table-cell; border: 1px solid red; height: 20px; width: 20px;">.</div> <div style="display: table-cell; border: 1px solid red;">.</div> <div style="display: table-cell; border: 1px solid red; height: 20px; width: 20px;">.</div> </div> <table style="width: 100%; border: 1px solid black; border-spacing: 0;"> <tr> <td style="width: 20px; border: 1px solid red;">.</td> <td style="border: 1px solid red;">.</td> <td style="width: 20px; border: 1px solid red;">.</td> </tr> </table> </body> </html>
Edit: it turns out that you get some unexpected behavior if you try to style the image as a cell table:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <style type="text/css"><![CDATA[ * {border: 1px solid black;} table, .table, .row { width: 100%; } .table { display: table; } .row { display: table-row; } .cell { display: table-cell; } img { height: 21px; width: 21px; } ]]></style> </head> <body> <div class="table"> <div class="row"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==" class="cell" /> <div class="cell"> </div> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==" class="cell" /> </div> </div> </body> </html>
The 2nd cell style element does not stretch completely horizontally to fill the rest of the width of the table. If you add content to it, it gradually does so. Weird
source share