


A detailed introduction to the calculation rules for table cell width in HTML
About the rendering rules of tablewidth
The calculation method of table cell width is mainly divided into two methods: Fixed table layout, automatic table layout, People who often write CSS should still know this, but we often find that setting the width of the table does not work, or it is rendered without a fixed width. Is this normal? Let’s introduce how these two methods calculate rendering.
First set a few common variables:
-
tableWidth=Table width=100%
tableBorderWidth=The left and right border width of the table
tdBorderWidth=The sum of the left and right border widths of all columns (the combined border is counted as 1px)
tdPadding=The left and right padding sum of all columns
tdWidth=The width sum of all columns with width defined
tdLength=number of columns
1. Fixed table layout, table additiontable-layout:fixed
ps: In a fixed table layout, the width of a table column has nothing to do with the column content. It is only related to the table width, column width, table left and right borders, column left and right borders, and column left and right padding
By using a fixed table layout, the user agent can display the table after receiving the first row, i.e. only the width of the first row will work
width is the width of the column with auto (i.e. where width is not defined The width of the column, if the calculation result is negative, it is 0) = (tableWidth-tableBorderWidth-tdBorderWidth-tdPadding-tdWidth)/tdLength
1. All th widths are undefined
The width of each column Evenly distributed by table width
th1 | th2 | th3 | th4 | th5 | th6 | th7 | th8 | th9 | th10 |
---|---|---|---|---|---|---|---|---|---|
row1row1row1row1row1row1row1row1 | row2row2row2row2row2row2row2row2 | row3 | row4row4row4row4row4row4row4row4 | row5row5row5row5row5row5row5row5 | row6 | row7row7row7row7row7row7row7row 7 | row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | row10row10row10row10row10row10row10 |
2. All th have a defined width, and the sum of the widths of all columns is less than Table width (tableBorderWidth+tdBorderWidth+tdPadding+tdWidth
The width of each column is evenly distributed through the total width; the width of the table is its defined width
th1 | th2 | th3 | th4 | th5 | th6 | th7 | th8 | th9 | th10 | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
row2row2row2row2row2row2row2row2 | row3 | row4row4row4row4row4row4row4row4 | row5row5row5row5row5row5row5row5 | row6 | row7row7row7row7row7row7row7row7 | row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | row10row10row10row10row10row10row10 |
th1 | th2 | th3 | th4 | th5 | th6 | th7 | th8 | th9 | th10 |
---|---|---|---|---|---|---|---|---|---|
row1row1row1row1row1row1row1row1 | row2row2row2row2row2row2row2row2 | row3 | row4row4row4row4row4row4row4row4 | row5row5row5row5row5row5row5row5 | row6 | row7row7row7row7row7row7row7row7 | row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | row10row10row10row10row10row10row10 |
4. The width of part th is set, and the width of the column with th width set at the same time is smaller than the table width (tableBorderWidth+tdBorderWidth+tdPadding+tdWidth
ps: Column with dark gray background For columns with a defined width
The width of a column with a defined width is its own defined width, and the width of other columns without a defined width is the total width of the table minus the sum of the defined widths and then evenly distributed
th1 | th2 | th3 | th4 | th5 | th6 | th7 | th8 | th9 | th10 |
---|---|---|---|---|---|---|---|---|---|
row1row1row1row1row1row1row1row1 | row2row2row2row2row2row2row2row2 | row3 | row4row4row4row4row4row4row4row4 | row5row5row5row5row5row5row5row5 | row6 | row7row7row7row7row7row7row7row 7 | row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | row10row10row10row10row10row10row10 |
5. Part of the th width is set, and the width of the column with the th width is set to be greater than Table width (tableBorderWidth+tdBorderWidth+tdPadding+tdWidth > tableWidth)
ps: The columns with dark gray background are columns with defined widths
The actual width of the columns with defined widths is self-defined Width, the width of other columns with no defined width is the total width of the table minus the sum of the defined widths and then evenly distributed. The width after even distribution is less than zero, then Other The width of other columns with no defined width is 0
th2 | th3 | th4 | th5 | th6 | th7 | #th8 | th9 | th10 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
row2row2row2row2row2row2row2row2 | row3 | row4row4row4row4row4row4row4row4 | row5row5row5row5row5row5row5row5 | row6 | row7row7row7row7row7row 7row7row7 | row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | row10row10row10row10row10row10row10 |
th2 | th3 | th4 | th5 | th6 | th7 | #th8 | th9 | th10 | |
---|---|---|---|---|---|---|---|---|---|
row2row2row2row2row2row2row2row2 | row3 | row4row4row4row4row4row4row4row4 | row5row5row5row5row5row5row5row5 | row6 | row7row7row7row7row7row 7row7row7 | row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | row10row10row10row10row10row10row10 |
th2 | th3 | th4 | th5 | th6 | th7 | #th8 | th9 | th10 | |
---|---|---|---|---|---|---|---|---|---|
row2row2row2row2row2row2row2row2 | row3 | row4 | row5 | row6 | row7 | row8 | row9 | row10 |
th3 | th4 | th5 | th6 | th7 | th8 | th9 | th10 | ##row1 | |
---|---|---|---|---|---|---|---|---|---|
row4row4row4row4row4row4row4row4 | row5 | row6row6row6row6row6row6row6row6 | row7 | row6row6row6row6row6row6row6row6 | row9 | row10row10row10row10row10row10row10 | 4. Part th defines the minimum width, and the sum of all columns calculated based on the content is less than the table width |
##th1
th4 | th5 | th6 | th7 | #th8 | th9 | th10 | row1 | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
row4row4row4row4row4row4row4row4 | row5 | row6 | row7 | row6 | row9 | row10 |
5. Part th defines the minimum width, and the sum of all columns calculated based on the content is less than the table widthps: The columns with dark gray background define the minimum width of the columns Every The column width is first calculated based on the content, and secondly it cannot be less than the defined minimum width
|
The above is the detailed content of A detailed introduction to the calculation rules for table cell width in HTML. For more information, please follow other related articles on the PHP Chinese website!

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

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

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment