admin管理员组文章数量:1323714
I want to have an Horizontal scroll bar to my table.
Html code:
As you can see i have already used bootstrap but still it is not working. in other modules it is working fine. The tbody data is added after an ajax is called.
I have also tried with :
overflow-x: auto
white-space: nowrap
The data is not showing properly to the right side: it is going outside the screen size i have to zoom it out to see the whole table.
<div class="modal fade" id="new-modal">
<div class="tble-grid-wrapper">
<div class="table-responsive pl-3 pr-3">
<table id="selectedDevices" class="table table-sm table-striped" class="display">
<thead>
<tr>
<th>HEADER 1</th>
<th>HEADER 2</th>
<th>HEADER 3</th>
<th>HEADER 4</th>
<th>HEADER 5</th>
<th>HEADER 6</th>
<th>HEADER 7</th>
<th>HEADER 8</th>
<th>HEADER 9</th>
<th>HEADER 10</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
I want to have an Horizontal scroll bar to my table.
Html code:
As you can see i have already used bootstrap but still it is not working. in other modules it is working fine. The tbody data is added after an ajax is called.
I have also tried with :
overflow-x: auto
white-space: nowrap
The data is not showing properly to the right side: it is going outside the screen size i have to zoom it out to see the whole table.
<div class="modal fade" id="new-modal">
<div class="tble-grid-wrapper">
<div class="table-responsive pl-3 pr-3">
<table id="selectedDevices" class="table table-sm table-striped" class="display">
<thead>
<tr>
<th>HEADER 1</th>
<th>HEADER 2</th>
<th>HEADER 3</th>
<th>HEADER 4</th>
<th>HEADER 5</th>
<th>HEADER 6</th>
<th>HEADER 7</th>
<th>HEADER 8</th>
<th>HEADER 9</th>
<th>HEADER 10</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
Share
Improve this question
edited Mar 17, 2021 at 10:27
Kareem Dabbeet
3,9943 gold badges18 silver badges35 bronze badges
asked Mar 17, 2021 at 10:00
Amit RathodAmit Rathod
512 silver badges8 bronze badges
1
-
1
enclose your table in a div. Constrain this div to 100% width. Add
overflow-x:auto
to this div. – Jeremy Thille Commented Mar 17, 2021 at 10:03
2 Answers
Reset to default 5Enclose your table in a div (which is already done, in your case)
Constrain this div with
width:100vw
. This is bulletproof.width:100%
means "100% of the parent's width", but if the parent is already larger than the screen, it won't work.width:100vw
means "100% of the Viewport's Width" and does not depend on anything else.Add
overflow-x: auto
to allow horizontal scrollbar. Job done
Demo below
#new-modal {
width : 100vw;
overflow-x: auto;
}
<div class="modal fade" id="new-modal">
<div class="tble-grid-wrapper">
<div class="table-responsive pl-3 pr-3">
<table id="selectedDevices" class="table table-sm table-striped" class="display">
<thead>
<tr>
<th>HEADER 1</th>
<th>HEADER 2</th>
<th>HEADER 3</th>
<th>HEADER 4</th>
<th>HEADER 5</th>
<th>HEADER 6</th>
<th>HEADER 7</th>
<th>HEADER 8</th>
<th>HEADER 9</th>
<th>HEADER 10</th>
<th>HEADER 11</th>
<th>HEADER 12</th>
<th>HEADER 13</th>
<th>HEADER 14</th>
<th>HEADER 15</th>
<th>HEADER 16</th>
<th>HEADER 17</th>
<th>HEADER 18</th>
<th>HEADER 19</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal fade" id="new-modal" style="width:100%;overflow-x:scroll;">
<div class="tble-grid-wrapper">
<div class="table-responsive pl-3 pr-3">
<table id="selectedDevices" class="table table-sm table-striped" class="display">
<thead>
<tr>
<th>HEADER 1</th>
<th>HEADER 2</th>
<th>HEADER 3</th>
<th>HEADER 4</th>
<th>HEADER 5</th>
<th>HEADER 6</th>
<th>HEADER 7</th>
<th>HEADER 8</th>
<th>HEADER 9</th>
<th>HEADER 10</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
what you are looking for is width: 100%; overflow-x: scroll
本文标签: javascriptAdd Horizontal Scroll bar to table in htmlStack Overflow
版权声明:本文标题:javascript - Add Horizontal Scroll bar to table in html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742127852a2422023.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论