这里有一个JS Bin链接:http://jsbin.com/qiziyupo/4/edit?output
响应式表格无法缩小以适应面板。我该如何解决?
编辑:我正在寻找一种解决方案,使响应式表格可以调整大小以适应面板,而不必使面板更大。
编辑:我正在寻找一种解决方案,使响应式表格可以调整大小以适应面板,而不必使面板更大。
.table-responsive
类只设计为在移动设备上响应性。根据Bootstrap 3.1.1文档,通过将任何一个`.table`放在`.table-responsive`中来创建响应式表格,使它们在小于768像素的设备上水平滚动。在宽度大于768像素的任何设备上查看时,这些表格不会有任何区别。
但是你可以将该类添加到您的CSS中,而无需媒体查询,并在任何视口中获得功能。
但请注意,这并不会缩小表格,只会提供水平滚动条...
以下是Bootstrap的.table-responsive
类,没有将其限制为768像素及以下的媒体查询。
.table-responsive {
width: 100%;
margin-bottom: 15px;
overflow-y: hidden;
overflow-x: scroll;
-ms-overflow-style: -ms-autohiding-scrollbar;
border: 1px solid #ddd;
-webkit-overflow-scrolling: touch;
}
.table-responsive>.table {
margin-bottom: 0;
}
.table-responsive>.table>thead>tr>th,
.table-responsive>.table>tbody>tr>th,
.table-responsive>.table>tfoot>tr>th,
.table-responsive>.table>thead>tr>td,
.table-responsive>.table>tbody>tr>td,
.table-responsive>.table>tfoot>tr>td {
white-space: nowrap;
}
还有几个CSS规则适用于.table-bordered
,我没有包括在内...
<div class="panel-body" style="overflow:scroll">
<table class="table table-bordered">
只需在面板区域中编写以下内容即可实现表格水平滚动。
这是因为Panel有这个类:
.col-md-3 {
width: 25%;
}
这是强制宽度的问题。去掉它,一切都会没问题的 :-)
使用容器也会对其产生影响。如果您的布局没有固定布局,请使用container-fluid
,并且.table
类的响应性就不会有任何问题。