实现滚动体

Dil*_*kar 6 css materialize

设置tbody高度宽度时我遇到问题overflow-y: scroll.

我试过这个CSS

.table-status-sheet tbody{
  min-height: 300px;
  overflow-y: auto;
}
Run Code Online (Sandbox Code Playgroud)

这是我的表格代码

 <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>
Run Code Online (Sandbox Code Playgroud)

此代码在引导程序中工作,但在"物化"主题中不起作用.请帮我解决这个问题.

Muh*_*mad 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%;
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)


Gab*_*x0r 0

在另一个问题中找到的解决方案: 如何使用溢出滚动设置 tbody 高度

你必须将 tbody 设置为 -> display:block;

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;
    }
Run Code Online (Sandbox Code Playgroud)