bootstrap table 上的滚动条

Scrollbar on bootstrap table

我有 tablepanel 内呈现,在 modal 内呈现。由于 table 相对较大,我想将它的行数限制为 5,这样模式就不会变得可滚动。我查看了 SO 和 google ,到处都看到我需要设置 overflow-y:autooverflow-y:scroll 才能让它工作,但在我的例子中,它没有。我还设置了 400px 和 position:absolute 的随机高度。这使 table 可以滚动,但现在面板以 <thead> 关闭并且 table 的主体呈现在面板之外。有什么办法解决这个问题?

我的代码片段是:

<div class="modal fade">
   <div class="modal-dialog " >
      <div class="modal-content">
         <div class="modal-body">
            <div class="panel panel-default">
               <div class="panel-body">
                  <table class="table table-bordered>
                     <thead>
                         [........]
                     </thead>
                     <tbody style="overflow-y:auto; height:400px; position:absolute>
                     [.......]
                     </tbody>
                   </table>

[...其余 </div>s...]


编辑

感谢您的回复。有没有办法单独将滚动条缩小到 <tbody>,以便 <thead> 保持静态?

在我给你举个例子后试一试

table,tr,th,td{
  border:1px solid #dddddd;
  border-collapse:collapse;
}
.tbl-header{
  width:calc(100% - 17px);
  width:-webkit-calc(100% - 17px);
  width:-moz-calc(100% - 17px);
}
<div class="tbl-header">
<table style="width:100%;">
  <thead>
<tr>
 <th width="50%">1</th>
  <th width="50%">2</th>
 </tr>
 </thead>
</table>
  </div>
<div style="width:100%;overflow:auto; max-height:100px;">
   <table style="width:100%;">
     <tr>
     <td width="50%">dsada</td>
       <td width="50%">dsadas</td>
     </tr>
     <tr>
     <td>dsada</td>
       <td>dsadas</td>
     </tr>
     <tr>
     <td>dsada</td>
       <td>dsadas</td>
     </tr>
     <tr>
     <td>dsada</td>
       <td>dsadas</td>
     </tr>
     <tr>
     <td>dsada</td>
       <td>dsadas</td>
     </tr>
     <tr>
     <td>dsada</td>
       <td>dsadas</td>
     </tr>
    
    </table>
   </div>

将其包裹在 table-responsive 中并设置最大高度:

.table-responsive {
    max-height:300px;
}

http://www.codeply.com/go/S6MgKWqFvj

这是演示

#collapse1{
overflow-y:scroll;
height:200px;
  <link rel="stylesheet" 

href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
  <h2>Collapsible List with table</h2>
  <div class="panel-group">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="panel-title">
          <a data-toggle="collapse" href="#collapse1">Collapsible list group with table</a>
        </h4>
      </div>
      <div id="collapse1" class="panel-collapse collapse">
        <table class="table">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody  >
      <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
 <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
 <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
 <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
 <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
 <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
 <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
      <tr>
        <td>Mary</td>
        <td>Moe</td>
        <td>mary@example.com</td>
      </tr>
      <tr>
        <td>July</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
    </tbody>
  </table>
      </div>
    </div>
  </div>
</div>