0

I have an HTML table with a vertical scrollbar.

HTML:

<div className="table_wrapper">
    <table>
        <thead></thead>
        <tbody className="add-insurance_table_tbody">...</tbody>
    </table>
</div>

The UI looks like this:

Current UI

CSS:

&_tbody {
    height:calc(100vh - 350px);
    overflow:auto;
    overflow-x:hidden;
    display:block;
    width:100%;
    font-size: 12px;
}

Now I want to increase the width of the table and add a horizontal scrollbar. I modified the above CSS and increased the width of the table.

A horizontal scrollbar appeared, however no scrolling happens.

The UI now looks like this:

Updated UI

Tried CSS:

&_tbody {
    height:calc(100vh - 350px);
    overflow:auto;
    display:block;
    font-size: 12px;
    width:calc(100vh - 350px);
    overflow-x: scroll
}
Kelvin
  • 320
  • 4
  • 19
Jane Fred
  • 1,379
  • 7
  • 23
  • 47

2 Answers2

0

You're using overflow-x: scroll; If you want a vertical bar use overflow-y: scroll; Use this:

yourTable {
   overflow-x: hidden;
   overflow-y: scroll;
}
M4FI4S
  • 166
  • 7
0

First method:

overflow: scroll; // Scrollbar visible
overflow: auto;   // Scrollbar displayed when needed

Second method:

  1. Make display: block of your table
  2. Set overflow-x: 'auto'

    table{
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
41 72 6c
  • 1,600
  • 5
  • 19
  • 30