search

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
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
This Isn't Supposed to Happen: Troubleshooting the ImpossibleThis Isn't Supposed to Happen: Troubleshooting the ImpossibleMay 15, 2025 am 10:32 AM

What it looks like to troubleshoot one of those impossible issues that turns out to be something totally else you never thought of.

@keyframes vs CSS Transitions: What is the difference?@keyframes vs CSS Transitions: What is the difference?May 14, 2025 am 12:01 AM

@keyframesandCSSTransitionsdifferincomplexity:@keyframesallowsfordetailedanimationsequences,whileCSSTransitionshandlesimplestatechanges.UseCSSTransitionsforhovereffectslikebuttoncolorchanges,and@keyframesforintricateanimationslikerotatingspinners.

Using Pages CMS for Static Site Content ManagementUsing Pages CMS for Static Site Content ManagementMay 13, 2025 am 09:24 AM

I know, I know: there are a ton of content management system options available, and while I've tested several, none have really been the one, y'know? Weird pricing models, difficult customization, some even end up becoming a whole &

The Ultimate Guide to Linking CSS Files in HTMLThe Ultimate Guide to Linking CSS Files in HTMLMay 13, 2025 am 12:02 AM

Linking CSS files to HTML can be achieved by using elements in part of HTML. 1) Use tags to link local CSS files. 2) Multiple CSS files can be implemented by adding multiple tags. 3) External CSS files use absolute URL links, such as. 4) Ensure the correct use of file paths and CSS file loading order, and optimize performance can use CSS preprocessor to merge files.

CSS Flexbox vs Grid: a comprehensive reviewCSS Flexbox vs Grid: a comprehensive reviewMay 12, 2025 am 12:01 AM

Choosing Flexbox or Grid depends on the layout requirements: 1) Flexbox is suitable for one-dimensional layouts, such as navigation bar; 2) Grid is suitable for two-dimensional layouts, such as magazine layouts. The two can be used in the project to improve the layout effect.

How to Include CSS Files: Methods and Best PracticesHow to Include CSS Files: Methods and Best PracticesMay 11, 2025 am 12:02 AM

The best way to include CSS files is to use tags to introduce external CSS files in the HTML part. 1. Use tags to introduce external CSS files, such as. 2. For small adjustments, inline CSS can be used, but should be used with caution. 3. Large projects can use CSS preprocessors such as Sass or Less to import other CSS files through @import. 4. For performance, CSS files should be merged and CDN should be used, and compressed using tools such as CSSNano.

Flexbox vs Grid: should I learn them both?Flexbox vs Grid: should I learn them both?May 10, 2025 am 12:01 AM

Yes,youshouldlearnbothFlexboxandGrid.1)Flexboxisidealforone-dimensional,flexiblelayoutslikenavigationmenus.2)Gridexcelsintwo-dimensional,complexdesignssuchasmagazinelayouts.3)Combiningbothenhanceslayoutflexibilityandresponsiveness,allowingforstructur

Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)May 09, 2025 am 09:57 AM

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

See all articles

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

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools