2017-05-05 165 views
-8

我有一個已經回答了很多次的問題,但是我的需求是自定義的,我想要一個帶有固定標題和動態高度的HTMl表格以及更多記錄的滾動條小於10具有固定標題,滾動條和動態高度的HTML表格

I want horizontal scroll bar if table size increases more than 100% width. 
Vertical scroll bar needed if table has records more than 10 . 
But if table has less than 10 records than the size of the table 
should not be fixed up to 10 rows. 
I found lots solutions but table height is being fixed there to achieve scroll. 

下面是我的HTML代碼

<div class="table-responsive custom-table-responsive"> 
       <table id="demo_datatables" class="table table-bordered table-striped stripe hover row-border"> 
       <thead class ="div-head" > 
    <tr> 
    <th><b>Stage</b></th> 
    <th><b>Site</b></th> 
    <th><b>Resource Name</b></th> 
    <th><b>APS Relevant</b></th> 

    </tr> 
    </thead> 

      <tbody> 


       <tr> 
       <td>1</td> 
       <td>2</td> 
       <td>3</td> 
       <td>4</td> 
       </tr> 
       <tr> 
       <td>1</td> 
       <td>2</td> 
       <td>3</td> 
       <td>4</td> 
       </tr> 
       <tr> 
       <td>1</td> 
       <td>2</td> 
       <td>3</td> 
       <td>4</td> 
       </tr> 
       <tr> 
       <td>1</td> 
       <td>2</td> 
       <td>3</td> 
       <td>4</td> 
       </tr> 


       </tr> 

    </tbody> 


     </table> 
       </div> 

     </div> 




    And CSS Used here is as below 

    .custom-table-responsive { 
    overflow: auto; 
    height: 400px; 
} 
+2

你要我們只是使它爲你? –

+0

這不是一個編碼服務 - 請解釋你到目前爲止所嘗試的內容,並顯示一些代碼。 – Stender

+0

在你的問題中沒有代碼,所以請更新你的問題,你已經嘗試 –

回答

0

今天,我有一個很好的一天,記住,我最近回答了這樣一個問題。

這很容易與CSS。

table{ 
     width: 500px; 
    } 

    th, td { 
    text-align: center; 
    min-width:200px; 
    } 

    td:nth-child(1), th:nth-child(1) { 
     min-width: 100px; 
    } 

    thead { 
     background-color: #000; 
     color: #fff; 
    } 

    thead tr { 
     display: block; 
     position: relative; 
    } 

tbody { 
    display: block; 
    overflow: auto; 
    overflow-x:hidden; 
    width: 100%; 
    height: 150px; 
} 

tbody tr:nth-child(even) { 
    background-color: #dddddd; 
} 

play with the sourece: JSBIN

相關問題