HTML&CSS 高级表格 可访问性进阶

过度构造的表格将带来很大的可访问性问题。

这时,可以使用scope属性。

scope属性是应用于表头的,它有两个可选值:row和col。

一个例子如下:

HTML代码如下:

<table>
      <caption>Train times and departures</caption>   
      <tr>     
        <td></td> <!-- empty cell in the top-right corner -->     
        <th scope="col">Departure Time</th>
        <th scope="col">Platform</th>
        <th scope="col">Buffet Coach</th>
      </tr>
      <tr>
        <th scope="row">Southampton</th>
        <td>13:03</td> 
        <td>12</td> 
        <td>Yes</td> 
      </tr>
      <tr> 
        <th scope="row">Edinburgh</th>
        <td>14:47</td>
        <td>4</td>
        <td>Yes</td>
      </tr>
      <tr>
        <th scope="row">Newcastle</th>
        <td>15:55</td>
        <td>7</td>
        <td>No</td>
      </tr>
    </table>

CSS代码如下:

table {
        border-collapse: collapse;
        border: 1px solid black;
      }
      th {
        text-align: left;
        border: 1px solid black;
        padding: 0.2em;
      }
      td {
        border: 1px solid black;
        padding: 0.2em;
      }


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值