[CSS] RWD Table


HTML

  1. <table>
  2. <thead>
  3. <tr>
  4. <th>CODE</th>
  5. <th>STOCK</th>
  6. <th>CAP</th>
  7. <th>INCH</th>
  8. <th>BOX TYPE</th>
  9. </tr>
  10. <thead>
  11. <tbody>
  12. <tr>
  13. <td>CES-9000</td>
  14. <td>50mt</td>
  15. <td>9mm</td>
  16. <td>1/2"</td>
  17. <td>Kangal / Coil</td>
  18. </tr>
  19. <tr>
  20. <td>CES-9000</td>
  21. <td>50mt</td>
  22. <td>9mm</td>
  23. <td>1/2"</td>
  24. <td>Kangal / Coil</td>
  25. </tr>
  26. <tr>
  27. <td>CES-9000</td>
  28. <td>50mt</td>
  29. <td>9mm</td>
  30. <td>1/2"</td>
  31. <td>Kangal / Coil</td>
  32. </tr>
  33. <tr>
  34. <td>CES-9000</td>
  35. <td>50mt</td>
  36. <td>9mm</td>
  37. <td>1/2"</td>
  38. <td>Kangal / Coil</td>
  39. </tr>
  40. </tbody>
  41. <table/>

CSS

  1. table {
  2. border-spacing: 1;
  3. border-collapse: collapse;
  4. background: white;
  5. border-radius: 6px;
  6. overflow: hidden;
  7. max-width: 800px;
  8. width: 100%;
  9. margin: 0 auto;
  10. position: relative;
  11. }
  12. table * {
  13. position: relative;
  14. }
  15. table td, table th {
  16. padding-left: 8px;
  17. }
  18. table thead tr {
  19. height: 60px;
  20. background: #FFED86;
  21. font-size: 16px;
  22. }
  23. table tbody tr {
  24. height: 48px;
  25. border-bottom: 1px solid #E3F1D5;
  26. }
  27. table tbody tr:last-child {
  28. border: 0;
  29. }
  30. table td, table th {
  31. text-align: left;
  32. }
  33. table td.l, table th.l {
  34. text-align: right;
  35. }
  36. table td.c, table th.c {
  37. text-align: center;
  38. }
  39. table td.r, table th.r {
  40. text-align: center;
  41. }
  42.  
  43. @media screen and (max-width: 35.5em) {
  44. table {
  45. display: block;
  46. }
  47. table > *, table tr, table td, table th {
  48. display: block;
  49. }
  50. table thead {
  51. display: none;
  52. }
  53. table tbody tr {
  54. height: auto;
  55. padding: 8px 0;
  56. }
  57. table tbody tr td {
  58. padding-left: 45%;
  59. margin-bottom: 12px;
  60. }
  61. table tbody tr td:last-child {
  62. margin-bottom: 0;
  63. }
  64. table tbody tr td:before {
  65. position: absolute;
  66. font-weight: 700;
  67. width: 40%;
  68. left: 10px;
  69. top: 0;
  70. }
  71. table tbody tr td:nth-child(1):before {
  72. content: "Code";
  73. }
  74. table tbody tr td:nth-child(2):before {
  75. content: "Stock";
  76. }
  77. table tbody tr td:nth-child(3):before {
  78. content: "Cap";
  79. }
  80. table tbody tr td:nth-child(4):before {
  81. content: "Inch";
  82. }
  83. table tbody tr td:nth-child(5):before {
  84. content: "Box Type";
  85. }
  86. }
Demo

沒有留言:

技術提供:Blogger.