The following simple snippet leads to the creation of a single web page that occupies the available screen space with a header at the top, the footer at the bottom, and the main content takes up as much space as possible (with a dotted border to make viewing easier):
html, body { width: 100%; height: 100%; margin: 0; padding: 0; } body { display: flex; flex-flow: column; } h1, small { flex: 0 1 auto; } div { flex: 1 1 auto; border: 1px dotted; }
<!doctype html> <html> <body> <h1>Some Header</h1> <div>Some Text</div> <small>Some Footer</small> </body> </html>
If I change CSS and HTML instead of instead of table instead of div , it does not expand the table to consume available space:
html, body { width: 100%; height: 100%; margin: 0; padding: 0; } body { display: flex; flex-flow: column; } h1, small { flex: 0 1 auto; } table { flex: 1 1 auto; border: 1px dotted; }
<!doctype html> <html> <body> <h1>Some Header</h1> <table><tr><td>Some Content</td></tr></table> <small>Some Footer</small> </body> </html>
Why does the first version (with div ) work, and the second version (with table ) does not? And is there a way to fix the second example so that the table expands and consumes all available space (without entering scrollbars)?
Some notes: my table will have a number of headers (all with equal width) and several rows (all with equal width / height). I know that you can recreate the table using a bunch of div and more CSS, but going down this route, he feels that he is throwing a child with bath water (and, besides, I would not ask this question and find out if I just hacked it). Also, JavaScript is not available to me here (and it seems like it's superfluous).
I know enough CSS / HTML to get myself in trouble, but not enough to get rid of it ...
Edit: aavrug's suggestion to use display: flex for table makes the table expand properly to fill the area, but when I add a few rows / columns to the table, they are not longer than evenly distributed. I would like to keep the equidistance of the table cell.
html css flexbox css3 css-tables
Cornstalks
source share