Fixed header and scrollable body

后端 未结 6 650
面向向阳花
面向向阳花 2020-12-14 11:26

I have like 15 columns in the table. I want to scroll both horizontal and vertical and header should be fixed when I scroll vertical. I have tried various examples but no

6条回答
  •  遥遥无期
    2020-12-14 11:56

    I have found a system that is

    • Compatible with Internet Explorer 9 + Chrome + Firefox (Windows) and Safari (Mac)
    • Without using javascript
    • Using only une div and one table
    • Fixed header and footer (EXCEPT for IE), with scrollable body. Header and body with same column widths

    Result:enter image description here

    HTML:

      
        
          <%= f.label :cost_center %>
          Personal
          Dpto
        
      
      
        <% @cost_centers.each do |cc| %>
        
          <%= cc.nombre_corto %>
          <%= cc.cacentrocoste %>
          <%= cc.cacentrocoste_dpto %>
        
        <% end %>
      
      
        
          Mostrar mas usuarios
        
      
    
    

    CSS:

    div.cost_center{
      font-size:75%;
      margin-left:5px;
      margin-top:5px;
      margin-bottom: 2px;
      float: right;
      display: inline-block;
      overflow-y: auto;
      overflow-x: hidden;
      max-height:300px;  
    }
    
    div.cost_center label { 
      float:none;
      font-size:14px;
    }
    
    div.cost_center table{
      width:300px;
      border-collapse: collapse; 
      float:right;
      table-layout:fixed;
    }
    
    div.cost_center table tr{
      height:16px;
    }
    div.cost_center th{
      font-weight:normal;
    }
    
    div.cost_center table tbody{
      display: block;
      overflow: auto;
      max-height:240px;
    }
    
    div.cost_center table thead{
      display:block;
    }
    
    div.cost_center table tfoot{
      display:block;
    }
    div.cost_center table tfoot td{
      width:280px;
    }
    div.cost_center .cc{
      width:60px;
      text-align: center; 
      border: 1px solid #999;
    }
    
    div.cost_center .nombre{
      width:150px;
    }
    div.cost_center tbody .nombre{
      border: 1px solid #999;
    }
    
    div.cost_center table tfoot td{
     text-align:center;  
     border: 1px solid #999; 
    } 
    
    div.cost_center table th, 
    div.cost_center table td { 
      padding: 2px;
      vertical-align: middle; 
    }
    
    div.cost_center table tbody td {
      white-space: normal;
      font:  .8em/1.4em Verdana, sans-serif;
      color: #000;
      background-color: white;
    }
    div.cost_center table th.cabecera { 
      font:  0.8em/1.4em Verdana, sans-serif;
      color: #000;
      background-color: #FFEAB5;
    }
    

提交回复
热议问题