0

I have trying to make scrollable tbody in flexbox.

I got two flexbox and each flexbox has table in it.

When items in table are overflow I want to use vertical scrollbar in tbody.

But tables are in flexbox that has no fixed height.

What should I do to show vertical scrollbar in tbody?

.root {
  background-color:green;
  width: 200px;
  height: 200px;
  display: flex;
  flex-flow:column nowrap;
}

.container1 {
  display: flex;
  flex-grow:4;
  background-color:yellow;
}

.container1 tbody {
  overflow: auto;
}

.container2 {
  display: flex;
  flex-grow:3;
  background-color:blue;
}
<div class="root">
  <div class="container1">
    <table>
      <thead>
        <tr>
          <td>name</td>
          <td>age</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="container2">
      <table>
      <thead>
        <tr>
          <td>name</td>
          <td>age</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

Let me know if you need more info. thanks.

JillAndMe
  • 3,989
  • 4
  • 30
  • 57

2 Answers2

0

you should use overflow auto

css

.container1 {
  display: flex;
  flex-grow:4;
  background-color:yellow;
  overflow:auto;
}
Ranjith v
  • 1,032
  • 5
  • 15
0

I have made some changes please check !

.root {
  background-color:green;
  width: 60vw;
  height: 30vh;
  display: flex;
  flex-flow:column nowrap;
}

.container1 {
  display: flex;
  flex-grow:4;
  background-color:yellow;
  overflow-y: auto;
}


/* this flexbox is not appears!! */
.container2 {
  display: flex;
  flex-grow:3;
  background-color:blue;
}
<div class="root">
  <div class="container1">
    <table width="100%">
      <thead>
        <tr>
          <td>name</td>
          <td>age</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="container2">
  </div>
</div>
Amarjit Singh
  • 1,152
  • 7
  • 12