CSS display特性的table报表合理布局

日期:2021-01-20 类型:科技新闻 

关键词:网站建设,创建网站,免费建站平台,智能建站,企业建网站

新项目更新改造中遇到DIV+CSS完成的table,新要求必须在报表应用模块格合拼,在网上调研返现CSS display:table完成的table报表,沒有模块格的特性和款式,历经1番思索,坎坷实际了模块格的合拼,即选用正行嵌套循环1个独立的display:table的DIV,随后在嵌套循环的报表DIV內部根据操纵队伍数和队伍的高宽比,完成模块格合拼。本人提议全新升级完成应用<table> HTML标识便可

1、CSS display特性的报表合理布局有关特性的解释:

table    此元素会做为块级报表来显示信息(相近 <table>),报表前后左右带有换行符。
table-row-group    此元素会做为1个或好几个行的排序来显示信息(相近 <tbody>)。
table-header-group    此元素会做为1个或好几个行的排序来显示信息(相近 <thead>)。
table-footer-group    此元素会做为1个或好几个行的排序来显示信息(相近 <tfoot>)。
table-row    此元素会做为1个报表行显示信息(相近 <tr>)。
table-column-group    此元素会做为1个或好几个列的排序来显示信息(相近 <colgroup>)。
table-column    此元素会做为1个模块格列显示信息(相近 <col>)
table-cell    此元素会做为1个报表模块格显示信息(相近 <td> 和 <th>)
table-caption    此元素会做为1个报表题目显示信息(相近 <caption>)

2、示例编码

1、一般报表

XML/HTML Code拷贝內容到剪贴板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <meta charset="UTF⑻">  
  5. <title>display一般报表</title>  
  6. <style type="text/css">  
  7. .table, .table * {margin: 0 auto; padding: 0;font-size: 14px;font-family: Arial, 宋体, Helvetica, sans-serif;}   
  8. .table {display: table; width: 80%; border-collapse: collapse;}   
  9. .table-tr {display: table-row; height: 30px;}   
  10. .table-th {display: table-cell;font-weight: bold;height: 100%;border: 1px solid gray;text-align: center;vertical-align: middle;background-color:#E5E5E5;}   
  11. .table-td {display: table-cell; height: 100%;border: 1px solid gray; text-align: center;vertical-align: middle;}   
  12. </style>  
  13. </head>  
  14. <body>  
  15.     <div class="table">  
  16.         <div class="table-tr">  
  17.             <div class="table-th">省分/直辖市</div>  
  18.             <div class="table-th">GDP(亿元)</div>  
  19.             <div class="table-th">提高率</div>  
  20.         </div>  
  21.         <div class="table-tr">  
  22.             <div class="table-td">广东</div>  
  23.             <div class="table-td">72812</div>  
  24.             <div class="table-td">8.0%</div>  
  25.         </div>  
  26.         <div class="table-tr">  
  27.             <div class="table-td">河南</div>  
  28.             <div class="table-td">37010</div>  
  29.             <div class="table-td">8.3%</div>  
  30.         </div>  
  31.         <div class="table-tr">  
  32.             <div class="table-td">江苏省</div>  
  33.             <div class="table-td">70116</div>  
  34.             <div class="table-td">8.5%</div>  
  35.         </div>  
  36.     </div>  
  37. </body>  
  38. </html>   

运作实际效果

2、列合拼完成报表

完成思路:根据display:table的报表完成,沒有<table>的rowspan和colspan模块格合拼的完成,因此坎坷完成,将报表每行独立嵌套循环1个单独的报表,这样在嵌套循环的单独报表內部,模块格合拼就可以根据操纵嵌套循环报表的行数和列数和模块格的宽高来完成

XML/HTML Code拷贝內容到剪贴板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <meta charset="UTF⑻">  
  5. <title>根据display列合拼报表</title>  
  6. <style type="text/css">  
  7. .table, .table * {margin: 0 auto; padding: 0;font-size: 14px;font-family: Arial, 宋体, Helvetica, sans-serif;}   
  8. .table {display: table; width: 80%; border-collapse: collapse;}   
  9.   
  10. .table-tr {display: table-row; height: 30px;}   
  11. .table-th {display: table-cell;font-weight: bold;height: 100%;border: 1px solid gray;text-align: center;vertical-align: middle;background-color:#E5E5E5;}   
  12. .table-td {display: table-cell; height: 100%;}   
  13.   
  14. .sub-table {width: 100%;height: 100%;display: table;}   
  15. .sub-table-tr {display: table-row; height: 100%;}   
  16. .sub-table-td {display: table-cell; height: 100%;border: 1px solid gray; text-align: center;vertical-align: middle;}   
  17.   
  18. </style>  
  19. </head>  
  20. <body>  
  21.   
  22. <div class="table">  
  23.     <div class="table-tr">  
  24.         <div class="table-td">  
  25.             <div class="sub-table">  
  26.                 <div class="sub-table-tr">  
  27.                     <div class="table-th" style="width: 40%;">省分/直辖市</div>  
  28.                     <div class="table-th" style="width: 30%;">GDP(亿元)</div>  
  29.                     <div class="table-th" style="width: 30%;">提高率</div>  
  30.                 </div>  
  31.             </div>  
  32.         </div>  
  33.     </div>  
  34.     <div class="table-tr">  
  35.         <div class="table-td">  
  36.             <div class="sub-table">  
  37.                 <div class="sub-table-tr">  
  38.                     <div class="sub-table-td" style="width: 40%;">广东</div>  
  39.                     <div class="sub-table-td" style="width: 30%;">72812</div>  
  40.                     <div class="sub-table-td" style="width: 30%;">8.0%</div>  
  41.                 </div>  
  42.             </div>  
  43.         </div>  
  44.     </div>  
  45.     <div class="table-tr">  
  46.         <div class="table-td">  
  47.             <div class="sub-table">  
  48.                 <div class="sub-table-tr">  
  49.                     <div class="sub-table-td" style="width: 40%;">河南</div>  
  50.                     <div class="sub-table-td" style="width: 30%;">37010</div>  
  51.                     <div class="sub-table-td" style="width: 30%;">8.3%</div>  
  52.                 </div>  
  53.             </div>  
  54.         </div>  
  55.     </div>  
  56.     <div class="table-tr">  
  57.         <div class="table-td">  
  58.             <div class="sub-table">  
  59.                 <div class="sub-table-tr">  
  60.                     <div class="sub-table-td" style="width: 40%;">江苏省</div>  
  61.                     <div class="sub-table-td" style="width: 30%;">70116</div>  
  62.                     <div class="sub-table-td" style="width: 30%;">8.5%</div>  
  63.                 </div>  
  64.             </div>  
  65.         </div>  
  66.     </div>  
  67.     <div class="table-tr">  
  68.         <div class="table-td">  
  69.             <div class="sub-table">  
  70.                 <div class="sub-table-tr">  
  71.                     <div class="sub-table-td" style="width: 70%;">各省/直辖市GDP均值提高率</div>  
  72.                     <div class="sub-table-td" style="width: 30%;">8.26%</div>  
  73.                 </div>  
  74.             </div>  
  75.         </div>  
  76.     </div>  
  77. </div>  
  78. </body>  
  79. </html>  

运作实际效果

3、行合拼报表

行合拼的完成思路:与列合拼的完成思路相近,将有模块格合拼的列独立嵌套循环1个display为table的DIV,高宽比=单行高*模块格合拼数目地倍数,同行业的别的列一样均独立嵌套循环DIV,案例编码以下

XML/HTML Code拷贝內容到剪贴板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <meta charset="UTF⑻">  
  5. <title>根据display的行合拼报表</title>  
  6. <style type="text/css">  
  7. .table, .table * {margin: 0 auto; padding: 0;font-size: 14px;font-family: Arial, 宋体, Helvetica, sans-serif;}   
  8. .table {display: table; width: 80%; border-collapse: collapse;}   
  9.   
  10. .table-tr {display: table-row; height: 30px;}   
  11. .table-th {display: table-cell;font-weight: bold;height: 100%;border: 1px solid gray;text-align: center;vertical-align: middle;background-color:#E5E5E5;}   
  12. .table-td {display: table-cell; height: 100%;}   
  13.   
  14. .sub-table {width: 100%;height: 100%;display: table;}   
  15. .sub-table-tr {display: table-row; height: 100%;}   
  16. .sub-table-td {display: table-cell; height: 100%;border: 1px solid gray; text-align: center;vertical-align: middle;}   
  17.   
  18. </style>  
  19. </head>  
  20. <body>  
  21.   
  22. <div class="table">  
  23.     <div class="table-tr">  
  24.         <div class="table-td">  
  25.             <div class="sub-table">  
  26.                 <div class="sub-table-tr">  
  27.                     <div class="table-th" style="width: 40%;">省分/直辖市</div>  
  28.                     <div class="table-th" style="width: 30%;">GDP(亿元)</div>  
  29.                     <div class="table-th" style="width: 30%;">提高率</div>  
  30.                 </div>  
  31.             </div>  
  32.         </div>  
  33.     </div>  
  34.     <div class="table-tr">  
  35.         <div class="table-td">  
  36.             <div class="sub-table">  
  37.                 <div class="sub-table-tr">  
  38.                     <div class="sub-table-td" style="width: 40%;">广东</div>  
  39.                     <div class="sub-table-td" style="width: 30%;">72812</div>  
  40.                     <div class="sub-table-td" style="width: 30%;">8.0%</div>  
  41.                 </div>  
  42.             </div>  
  43.         </div>  
  44.     </div>  
  45.     <div class="table-tr" style="height:60px;">  
  46.         <div class="table-td">  
  47.             <div class="sub-table">  
  48.                 <div class="sub-table-tr">  
  49.                     <div class="sub-table-td" style="width: 40%; border: none;">  
  50.                         <div class="sub-table">  
  51.                             <div class="sub-table-tr" style="height:50%;">  
  52.                                 <div class="sub-table-td" style="width: 100%; height:50%;">  
  53.                                     河南   
  54.                                 </div>  
  55.                             </div>  
  56.                             <div class="sub-table-tr" style="height:50%;">  
  57.                                 <div class="sub-table-td" style="width: 100%; height:50%;">  
  58.                                     江苏省   
  59.                                 </div>  
  60.                             </div>  
  61.                         </div>  
  62.                     </div>  
  63.                     <div class="sub-table-td" style="width: 30%;border: none;">  
  64.                         <div class="sub-table">  
  65.                             <div class="sub-table-tr" style="height:50%;">  
  66.                                 <div class="sub-table-td" style="width: 100%; height:50%;">  
  67.                                     37010   
  68.                                 </div>  
  69.                             </div>  
  70.                             <div class="sub-table-tr" style="height:50%;">  
  71.                                 <div class="sub-table-td" style="width: 100%; height:50%;">  
  72.                                     70116   
  73.                                 </div>  
  74.                             </div>  
  75.                         </div>  
  76.                        
  77.                     </div>  
  78.                        
  79.                     <div class="sub-table-td" style="width: 30%;border: none;">  
  80.                         <div class="sub-table">  
  81.                             <div class="sub-table-tr">  
  82.                                 <div class="sub-table-td" style="width: 100%;">  
  83.                                     8.4%   
  84.                                 </div>  
  85.                             </div>  
  86.                         </div>  
  87.                     </div>  
  88.                 </div>  
  89.             </div>  
  90.         </div>  
  91.     </div>  
  92.     <div class="table-tr">  
  93.         <div class="table-td">  
  94.             <div class="sub-table">  
  95.                 <div class="sub-table-tr">  
  96.                     <div class="sub-table-td" style="width: 70%;">各省/直辖市GDP均值提高率</div>  
  97.                     <div class="sub-table-td" style="width: 30%;">8.26%</div>  
  98.                 </div>  
  99.             </div>  
  100.         </div>  
  101.     </div>  
  102. </div>  
  103. </body>  
  104. </html>   

运作实际效果:

以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助

原文:http://www.cnblogs.com/haoqipeng/p/5309491.html