2016-12-08 68 views
6

我在設置tbody高度寬度overflow-y: scroll時遇到問題。實現滾動tbody

我想這個CSS

.table-status-sheet tbody{ 
    min-height: 300px; 
    overflow-y: auto; 
} 

這是我的表碼

<div class="responsive-table table-status-sheet"> 
    <table class="bordered"> 
     <thead> 
     <tr> 
      <th class="center">No.</th> 
      <th class="center">Category</th> 
     </tr> 
     </thead> 
     <tbody> 
     <tr> 
      <td>1</td> 
      <td>Category1</td>     
     </tr> 
     <tr> 
      <td>2</td> 
      <td>Category2</td>     
     </tr> 
     <tr> 
      <td>3</td> 
      <td>Category3</td>     
     </tr> 
     <tr> 
      <td>4</td> 
      <td>Category4</td>     
     </tr> 
     </tbody> 
    </table> 
    </div> 

此代碼工作在引導,但在「物化」的主題沒有奏效。 請幫我解決這個問題。在其他Nexus Q發現

+0

您能給更多的代碼或任何鏈接預覽此代碼? – Sasikumar

+2

你不是唯一一個有這個問題的人......我也面臨着改變tbody高度的困難......它確實要求我應用它的css不會改變它的高度 – weinde

+0

@Muhammad怎麼樣? – weinde

回答

6

下面介紹如何做到這一點。

JSFiddle DEMO

tbody { 
 
display:block; 
 
height:150px; 
 
overflow:auto; 
 
} 
 
thead, tbody tr { 
 
display:table; 
 
width:100%; 
 
table-layout:fixed; 
 
} 
 
thead { 
 
width: calc(100% - 1em) 
 
} 
 
table { 
 
width:100%; 
 
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css" rel="stylesheet"/> 
 
<div class="responsive-table table-status-sheet"> 
 
    <table class="bordered"> 
 
     <thead> 
 
     <tr> 
 
      <th class="center">No.</th> 
 
      <th class="center">Category</th> 
 
     </tr> 
 
     </thead> 
 
     <tbody> 
 
     <tr> 
 
      <td>1</td> 
 
      <td>Category1</td>     
 
     </tr> 
 
     <tr> 
 
      <td>2</td> 
 
      <td>Category2</td>     
 
     </tr> 
 
     <tr> 
 
      <td>3</td> 
 
      <td>Category3</td>     
 
     </tr> 
 
     <tr> 
 
      <td>4</td> 
 
      <td>Category4</td>     
 
     </tr> 
 
     </tbody> 
 
    </table> 
 
    </div>

0

溶液:How to set tbody height with overflow scroll

必須設置TBODY到 - >顯示:塊;

table ,tr td{} 
    tbody { 
     display:block; 
     height:50px; 
     overflow:auto; 
    } 
    thead, tbody tr { 
     display:table; 
     width:100%; 
     table-layout:fixed; 
    } 
    thead { 
     width: calc(100% - 1em); 
    } 
    table { 
     width:400px; 
    }