Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollable table body using bootstrap4

Using Bootstrap-4 I am not able to apply scroll for table body with fixed header. I am using min-height as well as overflow for applying scroll to table body. Does bootstrap4 doesn't support scroll on table body? Below snippet explains the problem more clearly.

Am I going wrong somewhere?

.tbody {
  min-height:10px;
  overflow-y:scroll;
}
 <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  
  
  <div class="container">
          
  <table class="table table-bordered">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody class="tbody">
      <tr>
        <td>John</td>
        <td>Doe</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td>Mary</td>
        <td>Moe</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td>July</td>
        <td>Dooley</td>
        <td>[email protected]</td>
      </tr>
    </tbody>
  </table>
</div>
like image 438
coder12349 Avatar asked Jul 16 '18 11:07

coder12349


1 Answers

After setting display:block property to table you can set height and widths.

Try this:

table {
  display:block;
  height : <set your desired height>;
  overflow-y : scroll;
}
like image 90
krupesh Anadkat Avatar answered Oct 18 '22 14:10

krupesh Anadkat