Home Web Front-end CSS Tutorial Table Formatting

Table Formatting

Feb 26, 2025 am 11:06 AM

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.

Table Formatting

Table formatting object

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.

Table Formatting

Separate border rendering

Table Formatting

Folded border rendering

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.
  • autoRemaining 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.

Don't omit cells!

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 algorithm

If 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

Border of table object

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 collapseIn 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

attribute. In the space between cell borders, the backgrounds of rows, row groups, columns, and column groups are not visible. Only the table background is visible in the cell spacing.

When the border-spacing

property is set to

, 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

and

properties are ignored when using the collapsed border model. border-spacing empty-cells

(The following is the FAQ part. Due to space limitations, only the title is retained here. Please refer to the original text for the complete content)

  • Basic formatting steps for tables
  • How to make a table responsive
  • How to merge table cells
  • How to add borders to table
  • How to change the background color of a table
  • How to align text in table
  • How to add a title to a table
  • How to style the first row or column of a table in different ways
  • How to add hover effect to a table
  • How to make a form more accessible

The above is the detailed content of Table Formatting. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1673
14
PHP Tutorial
1278
29
C# Tutorial
1257
24
A Comparison of Static Form Providers A Comparison of Static Form Providers Apr 16, 2025 am 11:20 AM

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

A Proof of Concept for Making Sass Faster A Proof of Concept for Making Sass Faster Apr 16, 2025 am 10:38 AM

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

Weekly Platform News: HTML Loading Attribute, the Main ARIA Specifications, and Moving from iFrame to Shadow DOM Weekly Platform News: HTML Loading Attribute, the Main ARIA Specifications, and Moving from iFrame to Shadow DOM Apr 17, 2025 am 10:55 AM

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

Some Hands-On with the HTML Dialog Element Some Hands-On with the HTML Dialog Element Apr 16, 2025 am 11:33 AM

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

Paperform Paperform Apr 16, 2025 am 11:24 AM

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

Weekly Platform News: Text Spacing Bookmarklet, Top-Level Await, New AMP Loading Indicator Weekly Platform News: Text Spacing Bookmarklet, Top-Level Await, New AMP Loading Indicator Apr 17, 2025 am 11:26 AM

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

Where should 'Subscribe to Podcast' link to? Where should 'Subscribe to Podcast' link to? Apr 16, 2025 pm 12:04 PM

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

Options for Hosting Your Own Non-JavaScript-Based Analytics Options for Hosting Your Own Non-JavaScript-Based Analytics Apr 15, 2025 am 11:09 AM

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

See all articles