CSS: Table Layout
CSS can emulate HTML Table tag. So, traditional layout using the table tag can be done with pure CSS.
Example. CSS Table
Here is a example of CSS table rendered in your browser:
cat
dog
red
blue
milk
eggs
Code
<div class="xtable"> <div class="xrow"> <div class="xcell">cat</div> <div class="xcell">dog</div> </div> <div class="xrow"> <div class="xcell">red</div> <div class="xcell">blue</div> </div> <div class="xrow"> <div class="xcell">milk</div> <div class="xcell">eggs</div> </div> </div>
.xtable { border: solid thin red; display: table; } .xrow { display: table-row; } .xcell, .xcell { display: table-cell; border: solid thin red; }
CSS Properties for Table Layout
Here is a full list of values for the display attribute to emulate table tags.
| CSS | HTML |
|---|---|
display:table | HTML table |
display:table-row | tr (row) |
display:table-cell | td (table cell) |
| CSS | HTML |
|---|---|
display:table-caption | caption |
display:table-header-group | thead (table header row; th group) |
display:table-footer-group | tfoot (table footer row) |
| CSS | HTML |
|---|---|
display:table-row-group | tbody |
display:table-column | col |
display:table-column-group | colgroup |