Rumah > hujung hadapan web > html tutorial > 详解table设置表格有滚动条实例

详解table设置表格有滚动条实例

零下一度
Lepaskan: 2017-06-24 10:22:57
asal
2895 orang telah melayarinya

table 设置表格有滚动条。

少说多做,代码中有注释:

 1 <!DOCTYPE HTML> 
 <html> 
 <head> 
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 6         
 <title>设置表格有滚动条</title> 7         
 <style> 8             
 * { 9                 margin: 0;                 
 padding: 0;11             }
              table {               
              /*设置相邻单元格的边框间的距离*/                 
              border-spacing: 0;16                 /*表格设置合并边框模型*/          
                    border-collapse: collapse;18                 
                    text-align: center;19             }          
                    /*关键设置 tbody出现滚动条*/21             table tbody {   
                                  display: block;23                 
                                  height: 80px;               
                                  overflow-y: scroll;25             }
                                           table thead,            
                                           tbody tr {
                                                        
                                                        display: table;30                 width: 100%;31     
                                                                   
                                                        table-layout: fixed;32             }33             /*关键设置:滚动条默认宽度是16px 将thead的宽度减16px*/34             table thead {35                 width: calc( 100% - 1em)36             }37             38             39             table thead th {40                 background: #ccc;41             }42             43         </style>44     </head>45 46     <body>47         <table width="80%" border="1">48             <thead>49                 <tr>50                     <th>姓名</th>51                     <th>年龄</th>52                     <th>出生年月</th>53                     <th>手机号码</th>54                     <th>单位</th>55                 </tr>56             </thead>57             <tbody>58                 <tr>59                     <td>张三</td>60                     <td>18</td>61                     <td>1990-9-9</td>62                     <td>13682299090</td>63                     <td>阿里巴巴</td>64                 </tr>65                 <tr>66                     <td>李四</td>67                     <td>18</td>68                     <td>1990-9-9</td>69                     <td>13682299090</td>70                     <td>阿里巴巴与四十大盗</td>71                 </tr>72                 <tr>73                     <td>王五</td>74                     <td>18</td>75                     <td>1990-9-9</td>76                     <td>13682299090</td>77                     <td>腾讯科技</td>78                 </tr>79                 <tr>80                     <td>孟想</td>81                     <td>18</td>82                     <td>1990-9-9</td>83                     
                                                        <td>13682299090</td>
                                                                            
                                                        <td>浏阳河就业</td>85                 
                                                        </tr>86             
                                                        </tbody>87         
                                                        </table>88     </body>89 90 </html>
Salin selepas log masuk

效果:

 

Atas ialah kandungan terperinci 详解table设置表格有滚动条实例. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan