09-08-responsive-table.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Responsive Table example</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <style>
  8. .cars {
  9. font-family: "Lucida Sans", Verdana, Arial, sans-serif;
  10. width: 100%;
  11. border-collapse: collapse;
  12. }
  13. .cars caption {
  14. text-align: left;
  15. font-style: italic;
  16. border-bottom: 1px solid #ccc;
  17. }
  18. .cars tr:nth-child(even) {
  19. background-color: #eee;
  20. }
  21. .cars caption,
  22. .cars th,
  23. .cars td {
  24. text-align: left;
  25. padding: 0 .5em;
  26. line-height: 2;
  27. }
  28. .cars thead {
  29. border-bottom: 2px solid;
  30. }
  31. @media only screen and (max-width: 760px) {
  32. .cars {
  33. display: block;
  34. }
  35. .cars thead {
  36. display: none;
  37. }
  38. .cars tr {
  39. border-bottom: 1px solid;
  40. }
  41. .cars td, .cars th {
  42. display: block;
  43. float: left;
  44. width: 100%;
  45. -moz-box-sizing: border-box;
  46. box-sizing: border-box;
  47. }
  48. .cars th {
  49. font-weight: 600;
  50. border-bottom: 2px solid;
  51. padding-top: 10px;
  52. }
  53. .cars td:before {
  54. content: attr(data-label);
  55. width: 40%;
  56. display: inline-block;
  57. font-style: italic;
  58. }
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <table class="cars">
  64. <caption>Tesla car models</caption>
  65. <thead>
  66. <tr>
  67. <th scope="col">
  68. Model
  69. </th>
  70. <th scope="col">
  71. Top speed
  72. </th>
  73. <th scope="col">
  74. Range
  75. </th>
  76. <th scope="col">
  77. Length
  78. </th>
  79. <th scope="col">
  80. Width
  81. </th>
  82. <th scope="col">
  83. Weight
  84. </th>
  85. <th scope="col">
  86. Starting price
  87. </th>
  88. </tr>
  89. </thead>
  90. <tbody>
  91. <tr>
  92. <th scope="row">Model S</th>
  93. <td data-label="Top speed">201 km/h</td>
  94. <td data-lagel="Range">426 km</td>
  95. <td data-label="Length">4 976 mm</td>
  96. <td data-label="Width">1 963 mm</td>
  97. <td data-label="Weight">2 108 kg</td>
  98. <td data-label="Starting price">$69 900</td>
  99. </tr>
  100. <tr>
  101. <th scope="row" data-label="Model">Roadster</th>
  102. <td data-label="Top speed">201 km/h</td>
  103. <td data-lagel="Range">393 km</td>
  104. <td data-label="Length">3 946 mm</td>
  105. <td data-label="Width">1 873 mm</td>
  106. <td data-label="Weight">1 235 kg</td>
  107. <td data-label="Starting price">$109 000</td>
  108. </tr>
  109. </tbody>
  110. </table>
  111. </body>
  112. </html>