Bootstrap中的水平和垂直滚动表
我正在使用bootstrap设计一个表,响应一个。 直到它少了没有。 列,这很好。 使用固定标头,它工作正常。
JSFIDDLE VERTICAL SCROLLBAR
现在,我在表格中需要超过20列,它也应该是水平滚动的。
JSFIDDLE HORIZONTAL SCROLLBAR
我尝试让它们一起工作,用于垂直滚动的固定标题表和具有可滚动标题的水平滚动。
我试过这个:
.table-fixed thead { width: 97%; } .table-fixed tbody { height: 150px; overflow-y: auto; width: 100%; } .table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed th { display: block; } .table-fixed tbody td, .table-fixed thead>tr>th { float: left; border-bottom-width: 0; } .table-fixed thead { width: 97%; } .table-fixed tbody { height: 230px; overflow-y: auto; width: 100%; } .table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed th { display: block; } .table-fixed tbody td, .table-fixed thead>tr>th { float: left; border-bottom-width: 0; }
S.No. Name Balance Action S.No. Name Balance Action S.No. Name Balance Action 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed 1 Mike Adams 100000000000000 ewed
我刚刚添加了重复的行,以使表格可滚动。 如何使表格可以垂直滚动(带有固定标题)和水平滚动(带滚动标题)?
过了一会儿,我得到了一个解决方案,我的查询。 解决方案,使表可以垂直和水平滚动和响应
$('table').on('scroll', function() { $("#" + this.id + " > *").width($(this).width() + $(this).scrollLeft()); });
html { font-family: verdana; font-size: 10pt; line-height: 25px; } table { border-collapse: collapse; width: 300px; overflow-x: scroll; display: block; } thead { background-color: #EFEFEF; } thead, tbody { display: block; } tbody { overflow-y: scroll; overflow-x: hidden; height: 140px; } td, th { min-width: 100px; height: 25px; border: dashed 1px lightblue; overflow: hidden; text-overflow: ellipsis; max-width: 100px; }
sadasdasdfasdfasfasfasfa# Firstname Lastname Age City Country # Firstname Lastname Age City Country 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
sadasdasdfasdfasfasfasfa# Firstname Lastname Age City Country # Firstname Lastname Age City Country 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA