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>
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;orfloatas 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 😉