Html Bootstrap 4表响应式车身滚动条
使用引导4。我有一个响应表,我想在其中制作一个可滚动的tbody。表如下所示:Html Bootstrap 4表响应式车身滚动条,html,css,twitter-bootstrap,bootstrap-table,Html,Css,Twitter Bootstrap,Bootstrap Table,使用引导4。我有一个响应表,我想在其中制作一个可滚动的tbody。表如下所示: <div class="table-responsive"> <table class="table table-striped table-hover custom-table text-nowrap"> <thead> <tr> <th>row1</th> <th>row2&
<div class="table-responsive">
<table class="table table-striped table-hover custom-table text-nowrap">
<thead>
<tr>
<th>row1</th>
<th>row2</th>
<th>row2</th>
</tr>
</thead>
<tbody>
<!-- some rows -->
</tbody>
</table>
但是,此样式无法正常工作。tbody中的所有内容都向左移动。我有一个有效的例子。
我做错了什么?你试着喜欢这个吗 像这样改变你的css
.custom-table {
tbody {
height: 50px;
overflow-y: auto;
width: 100%;
display: block;
}
}
.custom table>tbody{
显示:块;
高度:50px;
溢出:自动;
}
.自定义表格>主题,主题tr{
显示:表格;
宽度:100%;
}
.custom table>thead{
宽度:100%
}
.定制桌{
宽度:100%;
}
第1行
第2行
第2行
文本1
文本2
文本3
文本4
文本5
文本6
文本7
文本8
文本9
你试过喜欢这个吗
像这样改变你的css
.custom-table {
tbody {
height: 50px;
overflow-y: auto;
width: 100%;
display: block;
}
}
.custom table>tbody{
显示:块;
高度:50px;
溢出:自动;
}
.自定义表格>主题,主题tr{
显示:表格;
宽度:100%;
}
.custom table>thead{
宽度:100%
}
.定制桌{
宽度:100%;
}
第1行
第2行
第2行
文本1
文本2
文本3
文本4
文本5
文本6
文本7
文本8
文本9
请勾选下面的内容,我更喜欢使用flexbox
。我还使用-webkit
和-ms
前缀来实现更大的跨浏览器兼容性
tbody , thead {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
tr {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
th,td {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
text-align: center;
}
tbody {
height: 50px;
overflow-y: auto;
}
thead {
padding-right: 20px;
}
由于
tbody
上的滚动条,我将padding right
设置为thead
,请检查下面的内容,我更喜欢使用flexbox
。我还使用-webkit
和-ms
前缀来实现更大的跨浏览器兼容性
tbody , thead {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
tr {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
th,td {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
text-align: center;
}
tbody {
height: 50px;
overflow-y: auto;
}
thead {
padding-right: 20px;
}
我将
padding right
设置为thead
,因为tbody
上的滚动条都很好,但是表格中的内容没有对齐。是否要文本居中?一切都很好,但是表格中的内容没有对齐。是否要文本居中?是的,但是表格将以标题thead滚动,我需要它保持在原位。是的,但是表格会滚动标题thead,我需要它保持在原位。