当然你也可以用CSS去样式化表格标题。然而,要在不同浏览器里获得同样的效果还需要一定的技巧,这个也留给各位去实践了。
表格释义:summary属性
一般人可以很容易的决定是否研究一下表格的细节,只要瞥一眼就可以看出表格有多大、大概有什么内容。但是使用屏幕阅读器的人就不是那么容易了,除非我们给表格加上summary属性。这样可以提供比<caption>标签更详细的描述。
sumary属性的内容不会被可视化浏览器显示,所以可以尽可能的让描述足够长,使得那些用“听”的浏览者了解表格的内容。当然也不要用过头了,当有需要的时候才加上summary属性,比如对于很复杂的表格,添加一个summary属性可以使用屏幕阅读器人比较简单的了解表格的内容。
<table summary="The number of employees and the foundation year of some imaginary companies.">
<caption>Table 1: Company data</caption>
<tr>
<th>Company</th>
<th>Employees</th>
<th>Founded</th>
</tr>
<tr>
<td>ACME Inc</td>
<td>1000</td>
<td>1947</td>
</tr>
<tr>
<td>XYZ Corp</td>
<td>2000</td>
<td>1973</td>
</tr>
</table>
缩写表头:abbr属性
当屏幕阅读器遇到一个表格,每一行会把表头连每一个数据单元格一起读出来。如果表头很长,听一遍一遍的读是十分乏味的。通过使用abbr属性,可以给那些长的表头提供简写形式,取代表头的内容。abbr属性是可选的,大部分情况表头还是(或许是应该)比较简短的。
稍微修改一下刚才的表格,让表头更长些,abbr属性就可以这样用:
<table summary="The number of employees and the foundation year of some imaginary companies.">
<caption>Table 1: Company data</caption>
<tr>
<th abbr="Company">Company Name</th>
<th abbr="Employees">Number of Employees</th>
<th abbr="Founded">Foundation Year</th>
</tr>
<tr>
<td>ACME Inc</td>
<td>1000</td>
<td>1947</td>
</tr>
<tr>
<td>XYZ Corp</td>
<td>2000</td>
<td>1973</td>
</tr>
</table>
Table 1: Company data Company Name Number of Employees Foundation Year
ACME Inc 1000 1947
XYZ Corp 2000 1973
.