css表格表头表尾固定,表身滚动
表头表尾固定,表身滚动实现用了3个table标签
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 <title>表头表尾固定,表身滚动</title> 6 <meta charset="utf-8" /> 7 <style> 8 *{margin:0;padding:0;} 9 .container{border: 1px #ccc solid;width: 90%;margin: 100px auto;} 10 .form-table{width: 100%;margin: 0 auto;text-align: center;table-layout: fixed;} 11 .form-table th{border-right: 1px #ccc solid;border-bottom: 1px #ccc solid;background: #F3F3F3;} 12 .form-table td{border-bottom: 1px #ccc solid;border-right: 1px #ccc solid;} 13 .fixed-tfoot tr td{background: #F3F3F3;border-bottom: none;} 14 .fixed-thead,.fixed-tfoot{padding-right:17px;} 15 .fixed-thead tr th,.fixed-tfoot tr td{height: 50px;font-size: 16px;text-align: center;} 16 .scroll-box{width: 100%;height: 300px;overflow: auto;overflow-x:hidden;} 17 .scroll-box tr{width: 100%;height: 40px;line-height: 20px;} 18 .scroll-box tr td{padding: 5px;} 19 .scroll-box tr:nth-child(odd) td{background-color: #ECE9D8;} 20 .tip{margin: 0 auto;text-align: center;color: red;line-height: 150%;font-size: 14px;} 21 </style> 22 </head> 23 <body> 24 <!--container--> 25 <div class="container"> 26 <!--【fixed-thead表头】--> 27 <table class="form-table fixed-thead" cellpadding="0" cellspacing="0"> 28 <tr> 29 <th>序号</th> 30 <th>姓名</th> 31 <th>性别</th> 32 <th>年龄</th> 33 </tr> 34 </table> 35 <!--【fixed-thead表头】--> 36 <!--【表身】--> 37 <div class="scroll-box"> 38 <table class="form-table" cellpadding="0" cellspacing="0"> 39 <tr> 40 <td>111111</td> 41 <td>张三张三张三张三</td> 42 <td>男男男男男</td> 43 <td>181818</td> 44 </tr> 45 <tr> 46 <td>111111</td> 47 <td>张三张三三张三张三</td> 48 <td>男男男男男</td> 49 <td>181818</td> 50 </tr> 51 <tr> 52 <td>111111</td> 53 <td>张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三</td> 54 <td>男男男男男</td> 55 <td>181818</td> 56 </tr> 57 <tr> 58 <td>111111</td> 59 <td>张三张三张三张三</td> 60 <td>男男男男男</td> 61 <td>181818</td> 62 </tr> 63 <tr> 64 <td>111111</td> 65 <td>张三张三张三张三</td> 66 <td>男男男男男</td> 67 <td>181818</td> 68 </tr> 69 <tr> 70 <td>111111</td> 71 <td>张三张三张三张三</td> 72 <td>男男男男男</td> 73 <td>181818</td> 74 </tr> 75 <tr> 76 <td>111111</td> 77 <td>张三张三张三张三</td> 78 <td>男男男男男</td> 79 <td>181818</td> 80 </tr> 81 <tr> 82 <td>111111</td> 83 <td>张三张三张三张三</td> 84 <td>男男男男男</td> 85 <td>181818</td> 86 </tr> 87 <tr> 88 <td>111111</td> 89 <td>张三张三张三张三</td> 90 <td>男男男男男</td> 91 <td>181818</td> 92 </tr> 93 <tr> 94 <td>111111</td> 95 <td>张三张三张三张三</td> 96 <td>男男男男男</td> 97 <td>181818</td> 98 </tr> 99 <tr> 100 <td>111111</td> 101 <td>张三张三张三张三</td> 102 <td>男男男男男</td> 103 <td>181818</td> 104 </tr> 105 <tr> 106 <td>111111</td> 107 <td>张三张三张三张三</td> 108 <td>男男男男男</td> 109 <td>181818</td> 110 </tr> 111 <tr> 112 <td>111111</td> 113 <td>张三张三张三张三</td> 114 <td>男男男男男</td> 115 <td>181818</td> 116 </tr> 117 <tr> 118 <td>111111</td> 119 <td>张三张三张三张三</td> 120 <td>男男男男男</td> 121 <td>181818</td> 122 </tr> 123 <tr> 124 <td>111111</td> 125 <td>张三张三张三张三</td> 126 <td>男男男男男</td> 127 <td>181818</td> 128 </tr> 129 <tr> 130 <td>111111</td> 131 <td>张三张三张三张三</td> 132 <td>男男男男男</td> 133 <td>181818</td> 134 </tr> 135 <tr> 136 <td>111111</td> 137 <td>张三张三张三张三</td> 138 <td>男男男男男</td> 139 <td>181818</td> 140 </tr> 141 <tr> 142 <td>111111</td> 143 <td>张三张三张三张三</td> 144 <td>男男男男男</td> 145 <td>181818</td> 146 </tr> 147 <tr> 148 <td>111111</td> 149 <td>张三张三张三张三</td> 150 <td>男男男男男</td> 151 <td>181818</td> 152 </tr> 153 <tr> 154 <td>111111</td> 155 <td>张三张三张三张三</td> 156 <td>男男男男男</td> 157 <td>181818</td> 158 </tr> 159 <tr> 160 <td>111111</td> 161 <td>张三张三张三张三</td> 162 <td>男男男男男</td> 163 <td>181818</td> 164 </tr> 165 <tr> 166 <td>111111</td> 167 <td>张三张三张三张三</td> 168 <td>男男男男男</td> 169 <td>181818</td> 170 </tr> 171 <tr> 172 <td>111111</td> 173 <td>张三张三张三张三</td> 174 <td>男男男男男</td> 175 <td>181818</td> 176 </tr> 177 <tr> 178 <td>111111</td> 179 <td>张三张三张三张三</td> 180 <td>男男男男男</td> 181 <td>181818</td> 182 </tr> 183 <tr> 184 <td>111111</td> 185 <td>张三张三张三张三</td> 186 <td>男男男男男</td> 187 <td>181818</td> 188 </tr> 189 </table> 190 </div> 191 <!--【表身】--> 192 <!--【fixed-tfoot表尾】--> 193 <table class="form-table fixed-tfoot" cellpadding="0" cellspacing="0"> 194 <tr> 195 <td>序号</td> 196 <td>姓名</td> 197 <td>性别</td> 198 <td>年龄</td> 199 </tr> 200 </table> 201 <!--【fixed-tfoot表尾】--> 202 </div> 203 <!--container--> 204 <p class="tip"> 205 实现:table表格,表头、表尾固定;表身内容随着内容增加,出现滚动条,滚动下拉滚动条显示内容;<br /> 206 这个demo是通过3个table来实现。表头,表尾的table实现固定不动。中间的table外面,嵌套一层div。设置div的高度并添加overflow:auto 207 来实现滚动条<br /> 208 </p> 209 </body> 210 </html>
示例演示:demo