Created
September 14, 2019 14:19
-
-
Save topleague/93dac1ae837c251af95ad8359be6b555 to your computer and use it in GitHub Desktop.
HTML and CSS for creating responsive table in Genesis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table> | |
<thead> | |
<tr> | |
<th>Features</th> | |
<th>iPhone 5</th> | |
<th>iPhone 6</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td>Prices</td> | |
<td>₹24,999</td> | |
<td>₹29,999</td> | |
</tr> | |
<tr> | |
<td>Battery Capacity</td> | |
<td>1440 mAh</td> | |
<td>1570 mAh</td> | |
</tr> | |
<tr> | |
<td>Screen Size</td> | |
<td>4 inches</td> | |
<td>4 inches </td> | |
</tr> | |
<tr> | |
<td>Resolution</td> | |
<td>640x1136 pixels</td> | |
<td>640x1136 pixels</td> | |
</tr> | |
<tbody> | |
</table> | |
Add the CSS code snippets to the style.css file of your active child theme. | |
/* Generic Styling, for Desktops/Laptops */ | |
table { | |
width: 100%; | |
border-collapse: collapse; | |
} | |
/* Zebra striping */ | |
tr:nth-of-type(odd) { | |
background: #eee; | |
} | |
th { | |
background: #00B289; | |
color: white; | |
font-weight: bold; | |
/*text-align: center!important;*/ | |
} | |
td, th { | |
padding: 6px; | |
border: 1px solid #ccc; | |
text-align: left; | |
} | |
/*td { | |
text-align: center; | |
}*/ | |
td:nth-child(1n), th:nth-child(1n), td:nth-child(2n), th:nth-child(2n), td:nth-child(3n), th:nth-child(3n) { | |
padding-left: 5%; | |
} | |
/* CSS FOR RESPONSIVE TABLE*/ | |
@media | |
only screen and (max-width: 480px), | |
(min-device-width: 768px) and (max-device-width: 1024px) { | |
/* Force table to not be like tables anymore */ | |
table, thead, tbody, th, td, tr { | |
display: block; | |
} | |
/* Hide table headers (but not display: none;, for accessibility) */ | |
thead tr { | |
position: absolute; | |
top: -9999px; | |
left: -9999px; | |
} | |
tr { border: 1px solid #ccc; } | |
td { text-align: left; } | |
td { | |
/* Behave like a "row" */ | |
border: none; | |
border-bottom: 1px solid #eee; | |
position: relative; | |
padding-left: 50%!important; | |
} | |
td:before { | |
/* Now like a table header */ | |
position: absolute; | |
/* Top/left values mimic padding */ | |
top: 6px; | |
left: 6px; | |
width: 45%; | |
padding-right: 10px; | |
white-space: nowrap; | |
} | |
td:first-child, th:first-child { | |
padding-left: 50%; | |
} | |
/* | |
Label the data | |
*/ | |
td:nth-of-type(1):before { content: "Featuers"; } | |
td:nth-of-type(2):before { content: "iPhone 5"; } | |
td:nth-of-type(3):before { content: "iPhone 5S"; } | |
td:nth-of-type(4):before { content: "Favorite Color"; } | |
td:nth-of-type(5):before { content: "Wars of Trek?"; } | |
td:nth-of-type(6):before { content: "Porn Name"; } | |
td:nth-of-type(7):before { content: "Date of Birth"; } | |
td:nth-of-type(8):before { content: "Dream Vacation City"; } | |
td:nth-of-type(9):before { content: "GPA"; } | |
td:nth-of-type(10):before { content: "Arbitrary Data"; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment