headers属性
th要素のheaders属性は、対応する見出しセル(th要素)を指定する属性。
| ブラウザ対応 | ![]() ![]() ![]() ![]() ![]() |
|---|
構文
<th headers="対応するth要素のid"></th>
対応するth要素のid
対応する見出しセル(th要素)のid属性値を指定する。半角スペース区切りで、複数指定することもできる。
サンプルコード
<table border="1"> <tr> <th id="thA">見出しセルA</th> <th id="thB">見出しセルB</th> <th id="thC">見出しセルC</th> </tr> <tr> <th id="th1" headers="thA">見出しセル1</th> <td headers="th1 thB">B-1</td> <td headers="th1 thC">C-1</td> </tr> <tr> <th id="th2" headers="thA">見出しセル2</th> <td headers="th2 thB">B-2</td> <td headers="th2 thC">C-2</td> </tr> <tr> <th id="th3" headers="thA">見出しセル3</th> <td headers="th3 thB">B-3</td> <td headers="th3 thC">C-3</td> </tr> </table>
サンプル
HTMLソースコード
<style scoped>
table.sampleTable td {
text-align: right;
}
</style>
<table border="1" class="sampleTable">
<tr>
<th rowspan="2" id="sampleSubject">科目</th>
<th id="sample1">1回目</th>
<th id="sample2">2回目</th>
<th id="sample3">3回目</th>
</tr>
<tr>
<th id="sample4">4回目</th>
<th id="sample5">5回目</th>
<th id="sample6">6回目</th>
</tr>
<tr>
<th rowspan="2" id="sampleSansuu" headers="sampleSubject">算数</th>
<td headers="sampleSansuu sample1">72</td>
<td headers="sampleSansuu sample2">88</td>
<td headers="sampleSansuu sample3">100</td>
</tr>
<tr>
<td headers="sampleSansuu sample1">57</td>
<td headers="sampleSansuu sample2">98</td>
<td headers="sampleSansuu sample3">93</td>
</tr>
<tr>
<th rowspan="2" id="sampleKokugo" headers="sampleSubject">国語</th>
<td headers="sampleSansuu sample1">90</td>
<td headers="sampleSansuu sample2">62</td>
<td headers="sampleSansuu sample3">55</td>
</tr>
<tr>
<td headers="sampleSansuu sample1">68</td>
<td headers="sampleSansuu sample2">98</td>
<td headers="sampleSansuu sample3">100</td>
</tr>
</table>
実際の表示
| 科目 | 1回目 | 2回目 | 3回目 |
|---|---|---|---|
| 4回目 | 5回目 | 6回目 | |
| 算数 | 72 | 88 | 100 |
| 57 | 98 | 93 | |
| 国語 | 90 | 62 | 55 |
| 68 | 98 | 100 |




