gpt4 book ai didi

HTML 列属性

转载 作者:可可西里 更新时间:2023-11-01 13:37:33 24 4
gpt4 key购买 nike

我只是想知道默认情况下是否是 HTML <table>元素隐式地将属性 scope="col"应用于 <th> 的第一组<thead> 中包含的元素元素?

当我在浏览器中呈现下面的第一组 HTML 时,它似乎自动检测到 <th>一月、二月、三月、四月等的单元格是列的标题。那么 scope="col"是否不需要添加到标记中,因为它会以这种方式自动呈现?

 <table>
<caption>2009 Employee Sales by Department</caption>
<thead>
<tr>
<th></th>
<th>Jan</th>
<th>Feb</th>
<th>March</th>
<th>April</th>
<th>May</th>
<th>June</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Firefox</th>
<td>37.1</td>
<td>36.6</td>
<td>36.3</td>
<td>35.8</td>
<td>35.2</td>
<td>34.4</td>
</tr>
</tr>
</tbody>
</table>

第二组标记包括添加到一月、二月、三月、四月等标记的 scope="col"。是否有必要?正如上面的例子似乎呈现这些 <th>作为没有范围“col”的列。

我知道 scope 属性在普通网络浏览器中没有视觉效果,但屏幕阅读器可以使用。那么是否应该为了更好的语义标记和可访问性而添加它?

<table>
<caption>2009 Employee Sales by Department</caption>
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Jan</th>
<th scope="col">Feb</th>
<th scope="col">March</th>
<th scope="col">April</th>
<th scope="col">May</th>
<th scope="col">June</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Firefox</th>
<td>37.1</td>
<td>36.6</td>
<td>36.3</td>
<td>35.8</td>
<td>35.2</td>
<td>34.4</td>
</tr>
</tr>
</tbody>
</table>

最佳答案

根据HTML5 spec , scope 属性默认为 auto:

The scope attribute's missing value default is the auto state.

这个值的特点是

The auto state makes the header cell apply to a set of cells selected based on context.

所以我假设,屏幕阅读器将能够正确检测上下文,这反过来意味着,您不必显式定义属性,除非您有一些特殊的实例或用例 rowgroupcolgroup 值。

关于HTML <th> 列属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12910922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com