如何将这个 4 列表转换为单列表,但仍保持表的可访问性
我想将此表 http://jsfiddle.net/B7SVK/ 从 4 列改为单列,因为我需要将此表格从桌面转换为移动网站,而移动设备的宽度有限。我不想在网页中水平滚动。
那么有没有一种方法可以将这个 4 列表格转换为单列表格,同时保持相关数据单元格和标题之间的可访问性和关联性
<table>
<caption>
Contact Information
</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Phone#</th>
<th scope="col">Fax#</th>
<th scope="col">City</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Joel Garner</th>
<td>412-212-5421</td>
<td>412-212-5400</td>
<td>Pittsburgh</td>
</tr>
<tr>
<th scope="row">Clive Lloyd</th>
<td>410-306-1420</td>
<td>410-306-5400</td>
<td>Baltimore</td>
</tr>
<tr>
<th scope="row">Gordon Greenidge</th>
<td>281-564-6720</td>
<td>281-511-6600</td>
<td>Houston</td>
</tr>
</tbody>
</table>
I want to make this table http://jsfiddle.net/B7SVK/ from 4 column to single column because I need to convert this table from Desktop to Mobile website and mobile device has limited width. and I don't want horizontal scrolling in webpage.
So is there a way to convert this 4 column table into single column table while maintaining the accessibility and association between relevant data cells and heading
<table>
<caption>
Contact Information
</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Phone#</th>
<th scope="col">Fax#</th>
<th scope="col">City</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Joel Garner</th>
<td>412-212-5421</td>
<td>412-212-5400</td>
<td>Pittsburgh</td>
</tr>
<tr>
<th scope="row">Clive Lloyd</th>
<td>410-306-1420</td>
<td>410-306-5400</td>
<td>Baltimore</td>
</tr>
<tr>
<th scope="row">Gordon Greenidge</th>
<td>281-564-6720</td>
<td>281-511-6600</td>
<td>Houston</td>
</tr>
</tbody>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过将表格内的所有元素更改为
display: block;
来完全重新设计表格的样式,例如,这只是一个广泛的扫描,因为您也可以让其中一些元素
display: inline;
或float
就好像它们是非表格元素一样。这取决于您希望单列的外观。也许生成的内容将有助于考虑表格标题(视觉关联)..即通过隐藏
元素并在“单元格”内容之前生成“标题”..将尝试制作一个示例小提琴
示例 JSFiddle
小提琴中的代码:
HTML: 我放置的注释将标题行放入
中,以便可以隐藏它
更新
根据评论
为 176px 的单列;尝试这个 CSS:
它将显示更改为:
更新的 Fiddle
一旦你意识到你可以设置样式以这种方式设置表格,即与任何其他元素相同 - 您几乎可以使其看起来像您想要的那样;)
You can completely re-style a table by changing all the elements inside a table to
display: block;
e.g.that's just a broad sweep, as you can just as well have some of them
display: inline;
orfloat
as if they were non-table elements.. it depends on what you want your single column to look like.and maybe generated content would help regards table headings (visual associations).. i.e. by hiding the
<th>
elements and generating the "heading" before the "cell" content.. will try to make a sample fiddleExample JSFiddle
Code in fiddle:
HTML: note I put the header row into a
<thead>
so it can be hiddenUpdated
as per comments to change to single column of 176px;
try this CSS:
which changes the display to this:
Updated Fiddle
Once you realise you can style a table in this way, i.e. the same as any other element - you can pretty much make it look how you want ;)