gpt4 book ai didi

html - 表格数据不在 div 下滚动

转载 作者:行者123 更新时间:2023-11-28 11:11:05 26 4
gpt4 key购买 nike

我试图在高度为自动时滚动表格数据。但它不会滚动表格数据。我希望它是滚动表而不是 div。这是我的代码

<style>
table tr td{background:#ffcc00; padding:10px}
</style>

<div style="position:absolute; height:auto; min-height:200px; overflow-y:scroll; width:100%; top: 130px; left: 0px; padding-bottom:30px;">
<table style="width:100%; height:auto">
<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>

<tr>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
<td>fdsfd</td>
</tr>
</table>
</div>

最佳答案

你已经设置了容器min-height,你应该设置max-height

Demo

HTML

<div class="table_wrapper">
<!-- Your table goes here -->
</div>

CSS

.table_wrapper {
position:absolute;
height:auto;
max-height:200px;
overflow-y:scroll;
width:100%;
top: 130px;
left: 0px;
padding-bottom:30px;
}

我不确定你为什么要为你的 div 元素使用 position: absolute;,但我认为你不需要它,但如果你想使用出于某种原因,而不是考虑将元素嵌套在 position: relative; 容器中

关于html - 表格数据不在 div 下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21981170/

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