How to Make a Simple Responsive Table

by Dinesh 2014-03-15 17:45:20

<h1>How to Make a Responsive Table</h1>Here is the simple table code to provide responsive feature for your table content.
<h2>Table Code</h2>
<table><thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dinesh</td>
<td>23</td>
<td>Coimbatore</td>
</tr>
</tbody>
</table>
<h2>CSS Code</h2>

table {
width: 100%;
border-collapse: collapse;
}
tr:nth-of-type(odd) {
background: #eee;
}
th {
background: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: left;
}

<h2>CSS Media Code</h2>
@media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {

table, thead, tbody, th, td, tr {
display: block;
}

thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}

tr { border: 1px solid #ccc; }

td {
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
}

td:before {
position: absolute;
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}

/*
Label the data
*/
td:nth-of-type(1):before { content: "Name"; }
td:nth-of-type(2):before { content: "Age"; }
td:nth-of-type(3):before { content: "Address"; }
td:nth-of-type(4):before { content: "Dinesh"; }
td:nth-of-type(5):before { content: "23"; }
td:nth-of-type(6):before { content: "Coimbatore"; }
}
616
like
0
dislike
0
mail
flag

You must LOGIN to add comments