Converting blogger HTML tables into Smart Responsive tables using CSS
Requirement: Make all HTML Tables in Blogspot responsive ,pretty & a bit smarter.
How: Its 2 step process.
How: Its 2 step process.
- Add CSS for styling to template
- Modify your Table Structure accordingly.
Here are some screenshots as well:
On Desktop:
On Mobile/Tablets/Phones:
2:Change your tables html structure as shown for below example table, observe data-label attribute in each td tag these turns into headings in small screens such as mobile/tablets <td data-label="Server Name">:
That's it...clear browser cache and hit reload!
On Desktop:
On Mobile/Tablets/Phones:
Steps:
<style>
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 1.5em;
margin: .5em 0 .75em;
}
table tr {
background-color: white;
border: 1px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
background-color: white;
}
table td {border-left: 1px solid #ddd;}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
@media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 1.3em;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: .625em;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: .8em;
text-align: right;
}
table td {border-left: 0px;}
table td::before {
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
}
</style>
2:Change your tables html structure as shown for below example table, observe data-label attribute in each td tag these turns into headings in small screens such as mobile/tablets <td data-label="Server Name">:
<table> <thead> <tr><th>Server Name</th><th>Trace Flag</th><th>Status</th><th>Global</th><th>Session</th></tr> </thead> <tbody> <tr><td data-label="Server Name">PRD-MSSQL01C</td><td data-label="Trace Flag">1222</td><td data-label="Status">1</td><td data-label="Global">1</td><td data-label="Session">0</td></tr> <tr><td data-label="Server Name">PRD-MSSQL01C</td><td data-label="Trace Flag">1224</td><td data-label="Status">1</td><td data-label="Global">1</td><td data-label="Session">0</td></tr> <tr><td data-label="Server Name">PRD-MSSQL01C</td><td data-label="Trace Flag">4136</td><td data-label="Status">1</td><td data-label="Global">1</td><td data-label="Session">0</td></tr> </tbody> </table>
That's it...clear browser cache and hit reload!
Comments
Post a Comment
Note:Please be gentle while commenting and avoid spamming as comment are anyways moderated thank you.