HTML Table: In-depth understanding of complexity and styles
This article discusses the complexity of HTML tables and its application of CSS styles in depth. HTML tables contain elements such as title, row group and column group, and the rendering order is: table, column group, column, row group, row group, and cells. The HTML table model is centered in behavior and is contained within the rows on the cell structure.
CSS provides ten table-related display
attribute values for controlling table styles. These values can also be applied to other elements, but anonymous table-related elements may need to be generated to render correctly.
The width of the table and its columns is determined by two algorithms: the fixed table layout algorithm and the automatic table layout algorithm. The former is not affected by the content of the table cell, while the latter requires checking every cell in the table, which can be very time-consuming for large tables.
CSS2 defines two models that render internal table object borders: separate border models and folded border models. The Separated Border Model allows only the cells and tables to have borders, while the Collapse Border Model allows the borders of rows, row groups, columns, column groups, and tables themselves to overlap in complex ways.
Properties of columns and column group elements
Only a few properties can be applied to elements with display
attribute value table-column
or table-column-group
: border attribute (only in the collapsed border model), background attribute (cells and rows have transparent background), width attribute and visibility attribute value collapse
(other visibility values will be ignored).
Table width algorithm
Unlike other block-level boxes, tables with width set to auto
and horizontal margins of zero will not fill their containing blocks. The table size will be determined by its content. You can use margin-left
and margin-right
to set auto
to center the table horizontally.
There are two algorithms for determining the width of the table column: the fixed table layout algorithm and the automatic table layout algorithm, specified by the table-layout
attribute (the values are fixed
and auto
respectively, and the initial value is auto
). If the table width is specified as auto
, an automatic table layout algorithm is usually used. For block-level tables (display
set to table
), the user agent can, but does not have to use a fixed table layout algorithm.
In the fixed table layout algorithm, the width of the columns and tables is not affected by the content of the table cells. The width of each column is determined as follows:
auto
The width of the first row cell with a width not auto
Remaining columns evenly allocate remaining horizontal space (minus any border or cell spacing). Since the first row cell is used to determine the column width, if a fixed table layout algorithm is used, no cells should be omitted from the first row. The behavior in this case is not defined in the CSS2.1 specification.
Automatic table layout algorithms usually require multiple traversals. The CSS2.1 specification suggests an algorithm for determining column widths, but user agents do not need to use it. The algorithm checks every cell in the entire table and calculates the minimum and maximum widths required to render each cell. These values are then used to determine the width of each column, which in turn may determine the width of the table itself.
Because each cell has to be checked, the automatic table layout algorithm can be very time consuming for tables with a large number of rows and/or columns.
Table height algorithmIf the value of the table height attribute is not
and the specified height is different from the row height sum (plus border or cell spacing), the behavior is undefined. The percentage value of the height attribute of rows, row groups, and cells is not defined. The property of each cell determines how it is aligned within the row. Only auto
, vertical-align
, baseline
and top
values are allowed. For any other value, bottom
will be used. middle
baseline
There are two models that render internal table object borders in CSS2: the separation border model and the collapse border model. You can use the
attribute to set its value to (initial value) or border-collapse
to select the preferred model. separate
collapse
In the decoupled border model, only cells (and table itself) can have borders; rows, row groups, columns and column groups cannot. The borders are drawn around the cells, separated by the vertical and horizontal distances specified by the
When the border-spacing
, the cells are not separated, and their borders (and the borders of rows, row groups, columns, column groups and table itself) will be collapsed in a rather complicated way ( or overlap). border-collapse
The collapse
properties are ignored when using the collapsed border model. border-spacing
empty-cells
The above is the detailed content of Table Formatting. For more information, please follow other related articles on the PHP Chinese website!