Generally speaking a table is made of six layers that in the combination with the chosen styling, make a CSS table layout. These layers, appearing hierarchically, are: table, column groups, columns, row groups, rows and cells.
The layout and styling are not strictly defined, as they depend on the design ideas and browsers performance.
There is only one property that may be used to override the browser's algorithm and that is the table-layout property.
The table-layout property contains following information:
- value: auto, fixed or inherit;
- initial: auto;
- applies to: table and inline-table elements;
- inherited: no;
- percentages: N/A;
- media: visual;
- computed value: as specified.
The value fixed makes the table layout fixed, while the value auto lets the browser controls the algorithm of the table's layout.
The table layout with the fixed algorithm depends on the table's width, the width of the columns, borders and cell spacing while it ignores the content of the cells.
The table width may be specified with the width property. A value of auto, for the cases when display is set to table or inline-display, will use the automatic table algorithm; however if the table is set to a block-level table in a normal flow, browser may use the regular algorithm for normal flow layouts when the width property is set to auto.
In the fixed layout the column width is determined as follows:
- A column element with the value other then auto will set the width to that given value.
- A cell in the first row with the value other then auto sets the width for the whole column; if the cell spans more then one column, the width is divided over two columns.
- Other remaining columns equally divide the remaining horizontal table space.
The table's width in the automatic algorithm basically depends on the width of the columns and their borders.
The algorithm is also heavily depending on the browsers and how they render content versus the layout or whether will they choose precision over speed, etc...
Dynamic table layout changes
To apply dynamic changes to the table's layout, the property visibility can be used. This property takes the value collapse for row, row group, column and column group elements. This value makes entire row or column to be removed from display while the space left gets available for other content. The content affected by the rows or columns collapsing ends up being clipped while the table's basic layout remains unchanged.
Example with CSS table's layout: