gpt4 book ai didi

html - Bootstrap 表不跟随宽度显示 : block

转载 作者:行者123 更新时间:2023-11-28 01:24:27 25 4
gpt4 key购买 nike


从昨天开始,我实际上遇到了麻烦。
我正在使用 Bootstrap 4 和表格。实际上,如果我将宽度设置为超过 13.5vw,则表格不会跟随。这是 fiddle https://jsfiddle.net/aq9Laaew/88681/
这是代码

HTML

            <table class="table table-striped datas-table table-sm rounded">
<thead>
<tr>
<th scope="col">Date of Visit</th>
<th scope="col">Duration</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
</tr>
</tbody>
</table>

然后是 CSS

CSS

.datas-table {
overflow: auto;
display: block;
border-radius: 5px;
margin-top: 0.2604166666666667vw;
margin-left: 0.5208333333333334vw;
height: 16.11111111111111vh;
width: 14.583333333333334vw;
border: 1px solid rgba(0,0,0,0.1);
background-color: #FFFFFF;
box-shadow: 0 0 10px 0 rgba(0,0,0,0.1);
}
.datas-table > tbody > tr > td:nth-child(2), .datas-table > thead > tr > th:nth-child(2) {text-align: right; padding-right: 1.1458333333333335vw;}
.datas-table > tbody > tr > td:nth-child(1), .datas-table > thead > tr > th:nth-child(1) {padding-left: 0.5729166666666667vw;}

正如您在 Fiddle 中看到的那样,表格似乎并没有跟随。我之所以要使用 display: block,是因为 overflow: auto,没有它,我的表格不会滚动,宽度也不会得到尊重

谢天谢地,

最佳答案

试试我的表格代码,

.viewTable {
table-layout:fixed;
margin:auto;
}
.thData, .tdData {
padding:8px;
text-align: center;
}
.theadData, tfoot {
background-color: #9ac9fb;
display:table;
width:100%;
}
.table-height .table .tdData {
vertical-align: middle !important;
}
.viewTable .tbodyData {
max-height:250px;
overflow:auto;
overflow-x:hidden;
display:block;
width:100%;
}
.item-dist .tbodyData {
height:490px;
overflow:auto;
overflow-x:hidden;
width:100%;
}



.tbodyData .trData {
display:table;
width:100%;
table-layout:fixed;
border-bottom: 1px solid #ffffff !important;
}
.table .theadData .thData {
border: none !important;
width: 10% !important;
text-align: center;
padding: 10px;
}
 <table align="center" class="table table-hover viewTable">
<thead class="theadData">
<tr class="trData">
<th class="thData">Column 1</th>

<th class="thData">Column 2</th>
<th class="thData">Column 3</th>


<th class="thData">Column 4</th>
</tr>
</thead>

<tbody class="tbodyData">

<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr> <tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr> <tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr> <tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>
<tr class="trData">
<td class="tdData">A</td>
<td class="tdData">B</td>
<td class="tdData">C</td>
<td class="tdData">D</td>

</tr>



</tbody>
</table>

关于html - Bootstrap 表不跟随宽度显示 : block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51325700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com