分享

HTML5+CSS3 表格设计(Table)

 竹林湘馆 2016-03-18

CSS样式:


[css] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <style>  
  2.   
  3. body {  
  4. width600px;  
  5. margin40px auto;  
  6. font-family'trebuchet MS''Lucida sans'Arial;  
  7. font-size14px;  
  8. color#444;  
  9. }  
  10.   
  11. table {  
  12. *border-collapsecollapse/* IE7 and lower */  
  13. border-spacing0;  
  14. width100%;  
  15. }  
  16.   
  17. .bordered {  
  18. bordersolid #ccc 1px;  
  19. -moz-border-radius: 6px;  
  20. -webkit-border-radius: 6px;  
  21. border-radius: 6px;  
  22. -webkit-box-shadow: 0 1px 1px #ccc;  
  23. -moz-box-shadow: 0 1px 1px #ccc;  
  24. box-shadow: 0 1px 1px #ccc;  
  25. }  
  26.   
  27. .bordered tr:hover {  
  28. background#fbf8e9;  
  29. -o-transition: all 0.1s ease-in-out;  
  30. -webkit-transition: all 0.1s ease-in-out;  
  31. -moz-transition: all 0.1s ease-in-out;  
  32. -ms-transition: all 0.1s ease-in-out;  
  33. transition: all 0.1s ease-in-out;  
  34. }  
  35.   
  36. .bordered td, .bordered th {  
  37. border-left1px solid #ccc;  
  38. border-top1px solid #ccc;  
  39. padding10px;  
  40. text-alignleft;  
  41. }  
  42.   
  43. .bordered th {  
  44. background-color#dce9f9;  
  45. background-image: -webkit-gradient(linear, left topleft bottom, from(#ebf3fc), to(#dce9f9));  
  46. background-image: -webkit-linear-gradient(top#ebf3fc#dce9f9);  
  47. background-image: -moz-linear-gradient(top#ebf3fc#dce9f9);  
  48. background-image: -ms-linear-gradient(top#ebf3fc#dce9f9);  
  49. background-image: -o-linear-gradient(top#ebf3fc#dce9f9);  
  50. background-image: linear-gradient(top#ebf3fc#dce9f9);  
  51. -webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8inset;  
  52. -moz-box-shadow:0 1px 0 rgba(255,255,255,.8inset;  
  53. box-shadow: 0 1px 0 rgba(255,255,255,.8inset;  
  54. border-topnone;  
  55. text-shadow0 1px 0 rgba(255,255,255,.5);  
  56. }  
  57.   
  58. .bordered td:first-child, .bordered th:first-child {  
  59. border-leftnone;  
  60. }  
  61.   
  62. .bordered th:first-child {  
  63. -moz-border-radius: 6px 0 0 0;  
  64. -webkit-border-radius: 6px 0 0 0;  
  65. border-radius: 6px 0 0 0;  
  66. }  
  67.   
  68. .bordered th:last-child {  
  69. -moz-border-radius: 0 6px 0 0;  
  70. -webkit-border-radius: 0 6px 0 0;  
  71. border-radius: 0 6px 0 0;  
  72. }  
  73.   
  74. .bordered th:only-child{  
  75. -moz-border-radius: 6px 6px 0 0;  
  76. -webkit-border-radius: 6px 6px 0 0;  
  77. border-radius: 6px 6px 0 0;  
  78. }  
  79.   
  80. .bordered tr:last-child td:first-child {  
  81. -moz-border-radius: 0 0 0 6px;  
  82. -webkit-border-radius: 0 0 0 6px;  
  83. border-radius: 0 0 0 6px;  
  84. }  
  85.   
  86. .bordered tr:last-child td:last-child {  
  87. -moz-border-radius: 0 0 6px 0;  
  88. -webkit-border-radius: 0 0 6px 0;  
  89. border-radius: 0 0 6px 0;  
  90. }  
  91.   
  92. /*----------------------*/  
  93.   
  94. .zebra td, .zebra th {  
  95. padding10px;  
  96. border-bottom1px solid #f2f2f2;  
  97. }  
  98.   
  99. .zebra tbody tr:nth-child(even) {  
  100. background#f5f5f5;  
  101. -webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8inset;  
  102. -moz-box-shadow:0 1px 0 rgba(255,255,255,.8inset;  
  103. box-shadow: 0 1px 0 rgba(255,255,255,.8inset;  
  104. }  
  105.   
  106. .zebra th {  
  107. text-alignleft;  
  108. text-shadow0 1px 0 rgba(255,255,255,.5);  
  109. border-bottom1px solid #ccc;  
  110. background-color#eee;  
  111. background-image: -webkit-gradient(linear, left topleft bottom, from(#f5f5f5), to(#eee));  
  112. background-image: -webkit-linear-gradient(top#f5f5f5#eee);  
  113. background-image: -moz-linear-gradient(top#f5f5f5#eee);  
  114. background-image: -ms-linear-gradient(top#f5f5f5#eee);  
  115. background-image: -o-linear-gradient(top#f5f5f5#eee);  
  116. background-image: linear-gradient(top#f5f5f5#eee);  
  117. }  
  118.   
  119. .zebra th:first-child {  
  120. -moz-border-radius: 6px 0 0 0;  
  121. -webkit-border-radius: 6px 0 0 0;  
  122. border-radius: 6px 0 0 0;  
  123. }  
  124.   
  125. .zebra th:last-child {  
  126. -moz-border-radius: 0 6px 0 0;  
  127. -webkit-border-radius: 0 6px 0 0;  
  128. border-radius: 0 6px 0 0;  
  129. }  
  130.   
  131. .zebra th:only-child{  
  132. -moz-border-radius: 6px 6px 0 0;  
  133. -webkit-border-radius: 6px 6px 0 0;  
  134. border-radius: 6px 6px 0 0;  
  135. }  
  136.   
  137. .zebra tfoot td {  
  138. border-bottom0;  
  139. border-top1px solid #fff;  
  140. background-color#f1f1f1;  
  141. }  
  142.   
  143. .zebra tfoot td:first-child {  
  144. -moz-border-radius: 0 0 0 6px;  
  145. -webkit-border-radius: 0 0 0 6px;  
  146. border-radius: 0 0 0 6px;  
  147. }  
  148.   
  149. .zebra tfoot td:last-child {  
  150. -moz-border-radius: 0 0 6px 0;  
  151. -webkit-border-radius: 0 0 6px 0;  
  152. border-radius: 0 0 6px 0;  
  153. }  
  154.   
  155. .zebra tfoot td:only-child{  
  156. -moz-border-radius: 0 0 6px 6px;  
  157. -webkit-border-radius: 0 0 6px 6px  
  158. border-radius: 0 0 6px 6px  
  159. }  
  160.   
  161. </style>  

HTML:
[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <h2>Highlighted rows, borders</h2>  
  2. <table class="bordered">  
  3. <thead>  
  4.   
  5. <tr>  
  6. <th>#</th>  
  7. <th>IMDB Top 10 Movies</th>  
  8. <th>Year</th>  
  9. </tr>  
  10. </thead>  
  11. <tr>  
  12. <td>1</td>  
  13. <td>The Shawshank Redemption</td>  
  14.   
  15. <td>1994</td>  
  16. </tr>  
  17. <tr>  
  18. <td>2</td>  
  19. <td>The Godfather</td>  
  20. <td>1972</td>  
  21. </tr>  
  22. <tr>  
  23.   
  24. <td>3</td>  
  25. <td>The Godfather: Part II</td>  
  26. <td>1974</td>  
  27. </tr>  
  28. <tr>  
  29. <td>4</td>  
  30. <td>The Good, the Bad and the Ugly</td>  
  31. <td>1966</td>  
  32.   
  33. </tr>  
  34. <tr>  
  35. <td>5</td>  
  36. <td>Pulp Fiction</td>  
  37. <td>1994</td>  
  38. </tr>  
  39. <tr>  
  40. <td>6</td>  
  41. <td>12 Angry Men</td>  
  42.   
  43. <td>1957</td>  
  44. </tr>  
  45. <tr>  
  46. <td>7</td>  
  47. <td>Schindler's List</td>  
  48. <td>1993</td>  
  49. </tr>  
  50. <tr>  
  51.   
  52. <td>8</td>  
  53. <td>One Flew Over the Cuckoo's Nest</td>  
  54. <td>1975</td>  
  55. </tr>  
  56. <tr>  
  57. <td>9</td>  
  58. <td>The Dark Knight</td>  
  59.   
  60. <td>2008</td>  
  61. </tr>  
  62. <tr>  
  63. <td>10</td>  
  64. <td>The Lord of the Rings: The Return of the King</td>  
  65. <td>2003</td>  
  66. </tr>  
  67.   
  68. </table>  
  69.   
  70. <br><br>  
  71.   
  72. <h2>Zebra stripes, footer</h2>  
  73. <table class="zebra">  
  74. <thead>  
  75. <tr>  
  76. <th>#</th>  
  77. <th>IMDB Top 10 Movies</th>  
  78. <th>Year</th>  
  79.   
  80. </tr>  
  81. </thead>  
  82. <tfoot>  
  83. <tr>  
  84. <td> </td>  
  85. <td></td>  
  86. <td></td>  
  87. </tr>  
  88. </tfoot>  
  89. <tr>  
  90.   
  91. <td>1</td>  
  92. <td>The Shawshank Redemption</td>  
  93. <td>1994</td>  
  94. </tr>  
  95. <tr>  
  96. <td>2</td>  
  97. <td>The Godfather</td>  
  98. <td>1972</td>  
  99.   
  100. </tr>  
  101. <tr>  
  102. <td>3</td>  
  103. <td>The Godfather: Part II</td>  
  104. <td>1974</td>  
  105. </tr>  
  106. <tr>  
  107. <td>4</td>  
  108. <td>The Good, the Bad and the Ugly</td>  
  109.   
  110. <td>1966</td>  
  111. </tr>  
  112. <tr>  
  113. <td>5</td>  
  114. <td>Pulp Fiction</td>  
  115. <td>1994</td>  
  116. </tr>  
  117.   
  118. <tr>  
  119. <td>6</td>  
  120. <td>12 Angry Men</td>  
  121. <td>1957</td>  
  122. </tr>  
  123. <tr>  
  124. <td>7</td>  
  125. <td>Schindler's List</td>  
  126.   
  127. <td>1993</td>  
  128. </tr>  
  129. <tr>  
  130. <td>8</td>  
  131. <td>One Flew Over the Cuckoo's Nest</td>  
  132. <td>1975</td>  
  133. </tr>  
  134. <tr>  
  135.   
  136. <td>9</td>  
  137. <td>The Dark Knight</td>  
  138. <td>2008</td>  
  139. </tr>  
  140. <tr>  
  141. <td>10</td>  
  142. <td>The Lord of the Rings: The Return of the King</td>  
  143.   
  144. <td>2003</td>  
  145. </tr>  
  146. </table>  


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约