大家好! 我在許多文章和課程中看到表格元素中的<tfoot>
應放置在<tbody>
元素之前。正確...但是,當我這樣做時,驗證程序(https://validator.w3.org)告訴我這是錯誤的,並且在此情況下我不能使用<tfoot>
。所以我決定在<tbody>
之後加上<tfoot>
,驗證器在我的代碼中沒有發現任何錯誤。 那麼......無論如何,正確的做法是什麼? 我還發現,似乎與其自己的規格:https://www.w3.org/TR/html51/tabular-data.html#the-tfoot-elementHTML5 - 2017正確的訂購方式<tbody>和<tfoot>元素?
1
A
回答
3
<tfoot>
spec規則were changed in December 2015 to disallow <tfoot>
before <tbody>
。
至於W3C規範去,去尋找相關要求的地方實際上是the part of the spec that states the rules for what is allowed in the <table>
element,它說:
順序爲:可選的
caption
元素,其次是零個或多個colgroup
元素隨後任選地跟隨元素,隨後是零個或多個元素或者一個或多個元素,隨後任選地與tfoot
元素,任選地與一個或多個腳本支持元素混合。
通知,上面寫着tfoot
是tbody
後允許的,但它並沒有說這是tbody
之前允許的。
0
A <table>
元件。 <tfoot>
必須出現在任何<caption>, <colgroup>, <thead>, <tbody>, or <tr>
元素之後。請注意,這是HTML5的要求。
元素不能放在任何<tbody>
和<tr>
元素之後。請注意,這與HTML5的上述規範要求直接抵觸。
<table border="1" align="center">
<caption>A table</caption>
<thead>
<tr>
<th colspan="3">Invoice #123456789</th>
<th>14 January 2025
</tr>
<tr>
<td colspan="2">
<strong>Pay to:</strong><br> Acme Billing Co.<br> 123 Main St.<br> Cityville, NA 12345
</td>
<td colspan="2">
<strong>Customer:</strong><br> John Smith<br> 321 Willow Way<br> Southeast Northwestershire, MA 54321
</td>
</tr>
</thead>
<tbody>
<tr>
<th>Name/Description</th>
<th>Qty.</th>
<th>@</th>
<th>Cost</th>
</tr>
<tr>
<td>Paperclips</td>
<td>1000</td>
<td>0.01</td>
<td>10.00</td>
</tr>
<tr>
<td>Staples (box)</td>
<td>100</td>
<td>1.00</td>
<td>100.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="3">Subtotal</th>
<td> 110.00</td>
</tr>
<tr>
<th colspan="2">Tax</th>
<td> 8% </td>
<td>8.80</td>
</tr>
<tr>
<th colspan="3">Grand Total</th>
<td>$ 118.80</td>
</tr>
</tfoot>
</table>
相關問題
- 1. 問題樣式HTML5語義元素,如<section>,<nav>和<article>
- 2. msb4067元素<State><Project>無法識別 - Visual Studio 2017
- 3. 7.1 <7.10 - 訂購號碼
- 4. 訂購項目<T>
- 5. 列表<T>訂購
- 6. 訂購DOM元素
- 7. 關注HTML5 <button>元素
- 8. 使用<figure>圖標元素? HTML5
- 9. HTML5 <a>元素不居中
- 10. 番石榴的三元運算符問題:無法從訂購<Comparable>轉換爲訂購<String>
- 11. jQuery和<dialog>元素
- 12. 訂購RDD元素的最佳方式Apache Spark
- 13. 的BindingList用的IList <T>數據源,元訂購
- 14. 如何分組和正確訂購
- 15. HTML5 pattern訂購號
- 16. 訂購正確使用`pattern`
- 17. HTML5 <video>元素不適用於Firefox,Opera和Safari
- 18. 春天:訂購<map>標籤
- 19. 如何訂購清單<string>?
- 20. <nav>和<section>元素不露面
- 21. 什麼是html <i>元素的正確用例?
- 22. CSS:active在IE9中的<a>元素上不正確工作
- 23. XQuery - 訂單未正確訂購
- 24. 確定是否已訂購IQueryable <T>
- 25. <body>元素上的樣式
- 26. xml <! >元素
- 27. Knockoutjs點擊綁定<option>元素是否正確?
- 28. <xsd:key>元素 - 如何正確使用它?
- 29. <activity>元素必須是<application>元素的直接子元素
- 30. <html>元素大於<body>
對於其他的信息(比如WordPress插件開發人員)在這裏結束了,驗證https://validator.w3.org/將着眼於網站的doctype,並重定向到https: //validator.w3.org/nu/ if <!DOCTYPE HTML>。這可能會令人困惑,因爲根據所使用的網站的文檔類型,相同的表tfoot html將是有效的或無效的。(顯然!)然而,似乎並不是所有文檔類型都有效的通用標準標準,也沒有辦法以確定所使用的doctype,據我所知,在生成表html之前。 – anmari