關於表格寬度的渲染規則
表格單元格寬度的計算方式主要分為兩種方式: 固定表格佈局、自動表格佈局,這個經常寫css的人應該還是知道的,但是我們經常會發現給表格列定了寬度不起作用,又或是沒有定寬度渲染出來的卻是正常的嗎,以下就來介紹下這兩個方式具體是怎麼計算渲染的。
先設定幾個通用的變數:
-
tableWidth=表格寬度=100%
tableBorderWidth=表格左右邊框寬度
tdBorderWidth=所有列左右邊框寬度和(合併的邊框算1px)
tdPadding=所有列左右內填補和
#tdWidth=所有定義了width的列的寬度和
#tdLength=列數
#一、固定表格佈局,表格新增table-layout:fixed
ps:在固定表格佈局中,表格列的寬度與列內容多少無關,只與表格寬度、列寬度、表格左右邊框、列左右邊框、列左右內填補有關
透過使用固定表格佈局,使用者代理程式在接收第一行後就可以顯示表格,即只有第一行的寬度才會起作用
width為auto的列的寬度(即未定義width的列的寬度,如果計算結果為負數則為0)= (tableWidth-tableBorderWidth-tdBorderWidth-tdPadding-tdWidth)/tdLength
1、所有th寬度未定義
#每列的寬度透過表格寬度平均分配
th1 | th2 | th3 | th4 | th5 | th6 | th7 | th8 | th9 | th10 |
---|---|---|---|---|---|---|---|---|---|
row1row1row1row1row1row1row1row1 | #row2row2row2row2row2row2row2 | #row3 | row4row4row4row4row4row4row4row4 | #row# 7 | row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | row10row10row10row10row10row10row10 |
#th1 | th2 | th3 | th4 | th5 | th6 | ||||
---|---|---|---|---|---|---|---|---|---|
th9 | th10 | row1row1row1row1row1row1row1row1 | #row2row2 row3 | row4row4row4row4row4row4row4row4 | #row5row5row5row5row5row#row5 |
3、所有th都定了寬度,同時所有列寬度總和大於表格寬度(tableBorderWidth+tdBorderWidth+tdPadding+tdWidth > tableWidth)
每列的寬度為自身定義的寬度;表格的寬度為所有列寬度總和(會超出表格定義的寬度)
th1 | ##th2th3 | th4 | th5 | th6 | th7 | th8 | th9 | th10 | |
---|---|---|---|---|---|---|---|---|---|
#row2row2row2row2row2row2row2 | row3 | row4 ##row5row5row5row5row5row5row5row5 | #row6 | #row7row7row7row7row7row7row7 | row8row8row8row8row8row8row8row8 | #row9 | ##4、部分th定了寬度,同時定了th寬度的列的寬度之後小於表格寬度(tableBorderWidth+tdBorderWidth+tdPadding+tdWidth ps:深灰色背景的列為定義了寬度的列 |
th1
th4 | th5 | th6 | th7 | th8 | th9 | th10 | row1row1row1row1row1row1row1row1 | ||
---|---|---|---|---|---|---|---|---|---|
row4row4row4row4row4row4row4row4 | #row# 7 | row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | row10row10row10row10row10row10row10 | ##5、部分th表格寬度(tableBorderWidth+tdBorderWidth+tdPadding+tdWidth > tableWidth) | ps:深灰色背景的列為定義了寬度的列 | #定義寬度的列的實際寬度為自身定義的寬度,其他沒有定義寬度的列的寬度為表格總寬度減去定義的寬度之和再平均分配,平均分配後的寬度小於零,則 | 其它沒有定義寬度的列的寬度為0 |
th4
th7 | th8 | th9 | th10 | row1row1row1row1row1row1row1row1 | row2row2row2row2row2row2row2row2 | #row | ##row4row4row4row4row4row4row4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
row8row8row8row8row8row8row8row8 | row9row9row9row9row9row9row9row9 | #row10row10row10row10row10row10row10 | ## |
th1 | #th2 | th3 | th4 | th5 | th6 | th7 | th8 | th9 | th10 |
---|---|---|---|---|---|---|---|---|---|
row1row1row1row1row1row1row1row1 | row2row2row2row2row2row2row2row2 | #row | ##row4row4row4row4row4row4row4 | row4row4row4row4row4row4 7row7row7 | row8row8row9列總和小於表格寬度 | 每列寬度先根據內容計算,同時不能小於定義的最小寬度,多餘的寬度每一列上面平均分配點。 |
th4
th7 | th8 | th9 | th10 | row1 | row2row2row2row2row2row2row2row2 | row3 | row4 | ||
---|---|---|---|---|---|---|---|---|---|
#row7 | row8 | row9 | row10 | #3、所有th都定義了最小寬度,根據內容計算的所有列之和大於表格寬度 | 每列寬度先根據內容計算,其次不能小於定義的最小寬度 |
th4
th7 | th8 | ||||||||
---|---|---|---|---|---|---|---|---|---|
##th10 | row2row2row2row2row2row2row2row2 | #row3 | row4row4row4row4row4row4row4row4 |
row6row6row6row6row6row6row6row6
#row7
row6row6row6
每列寬度先根據內容計算,其次不能小於定義的最小寬度,最後表格渲染出來的寬度不能小於表格本身定義的寬度。 | th1 | #th2 | th3 | th4 | th5 | th6 | |||
---|---|---|---|---|---|---|---|---|---|
th9 | th10 | row1 | row2 | row3 | #row4row4row4row4row4row4row4row4 | row5 | #row6 |
5、部分th定義了最小寬度,根據內容計算的所有列總和小於表格寬度
ps:深灰色背景的列為定義了最小寬度的列
每列寬度先根據內容計算,其次不能小於定義的最小寬度
#th1 | th2 | th3 | th4 | th5 | th6 | th7 | th8 | th9 | #th10 |
---|---|---|---|---|---|---|---|---|---|
#row1 | #row2row4row4row4row4row4 | ##row4row4row4row4row4row4row4 | ##row4row4row4row4row4row4row4 |
以上是html中關於表格單元格寬度的計算規則的具體介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

HTML代碼可以通過在線驗證器、集成工具和自動化流程來確保其清潔度。 1)使用W3CMarkupValidationService在線驗證HTML代碼。 2)在VisualStudioCode中安裝並配置HTMLHint擴展進行實時驗證。 3)利用HTMLTidy在構建流程中自動驗證和清理HTML文件。

HTML、CSS和JavaScript是構建現代網頁的核心技術:1.HTML定義網頁結構,2.CSS負責網頁外觀,3.JavaScript提供網頁動態和交互性,它們共同作用,打造出用戶體驗良好的網站。

HTML的功能是定義網頁的結構和內容,其目的在於提供一種標準化的方式來展示信息。 1)HTML通過標籤和屬性組織網頁的各個部分,如標題和段落。 2)它支持內容與表現分離,提升維護效率。 3)HTML具有可擴展性,允許自定義標籤增強SEO。

HTML的未來趨勢是語義化和Web組件,CSS的未來趨勢是CSS-in-JS和CSSHoudini,JavaScript的未來趨勢是WebAssembly和Serverless。 1.HTML的語義化提高可訪問性和SEO效果,Web組件提升開發效率但需注意瀏覽器兼容性。 2.CSS-in-JS增強樣式管理靈活性但可能增大文件體積,CSSHoudini允許直接操作CSS渲染。 3.WebAssembly優化瀏覽器應用性能但學習曲線陡,Serverless簡化開發但需優化冷啟動問題。

HTML、CSS和JavaScript在Web開發中的作用分別是:1.HTML定義網頁結構,2.CSS控製網頁樣式,3.JavaScript添加動態行為。它們共同構建了現代網站的框架、美觀和交互性。

HTML的未來充滿了無限可能。 1)新功能和標準將包括更多的語義化標籤和WebComponents的普及。 2)網頁設計趨勢將繼續向響應式和無障礙設計發展。 3)性能優化將通過響應式圖片加載和延遲加載技術提升用戶體驗。

HTML、CSS和JavaScript在網頁開發中的角色分別是:HTML負責內容結構,CSS負責樣式,JavaScript負責動態行為。 1.HTML通過標籤定義網頁結構和內容,確保語義化。 2.CSS通過選擇器和屬性控製網頁樣式,使其美觀易讀。 3.JavaScript通過腳本控製網頁行為,實現動態和交互功能。

HTMLISNOTAPROGRAMMENGUAGE; ITISAMARKUMARKUPLAGUAGE.1)htmlStructures andFormatSwebContentusingtags.2)itworkswithcsssforstylingandjavascript for Interactivity,增強WebevebDevelopment。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript開發工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),