Table Formatting
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:
-
The width of the column object with
- is not set to the width of the column.
auto
The width of the first row cell with a width not sets the width of the column to which it belongs. If the cells span multiple columns, the width is evenly distributed to those columns. -
auto
Remaining columns evenly allocate remaining horizontal space (minus any border or cell spacing). - Table width is the larger value in the table width attribute value and the sum of column widths (plus border or cell spacing). If the table is wider than the column, additional space is allocated to the column.
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

In this week's roundup of platform news, Chrome introduces a new attribute for loading, accessibility specifications for web developers, and the BBC moves

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and

Buy or build is a classic debate in technology. Building things yourself might feel less expensive because there is no line item on your credit card bill, but

In this week's roundup, a handy bookmarklet for inspecting typography, using await to tinker with how JavaScript modules import one another, plus Facebook's

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used
