需要在 html 表格中滚动单元格
我有一个 html 表,其中包含一个包含大量数据的单元格(可能有 200 行)。 我希望表格中的单元格滚动,而不是要求页面滚动。
我知道我需要一个 div
块来执行此操作。我在我的中定义了一个div块 css 文件,但它没有被占用。
如何修复单元格的高度并为我的数据提供滚动条?
--------html表格---------
<table class="cmain">
<tr>
<td> TOP LEFT CELL <p>
<table> <tr> <td> A sub-table goes here </td> </tr> </table>
</td>
<td> TOP RIGHT CELL <p>
<p> A PHOTO GOES HERE.
<p> PHOTO: {{ form.image }}
</td>
<td rowspan="2" valign="top" >
THIS IS THE CELL THAT NEEDS THE SCROLL BAR. <div id="scrollcell">
SCROLLER CELL <hr>
<p> {% for customer in customer_list %}
<p> {{ customer }} </p>
{% endfor %}
</div>
</td>
</tr>
<tr>
<td> Another Sub-table goes here.
<table> <tr> <td> A sub-table goes here </td> </tr> </table>
</td>
<td> A NOTES FORM FIELD GOES HERE <p>
{{ form.notes }} </td>
</tr>
</table> <!-- end of CMAIN table -->
--------css -----------
table, th, td {
border: 1px solid white;
}
table.cmain {
border: 1px solid blue;
}
table.cmain td {
border: 1px solid blue;
font-weight: bold;
/*width: 300;*/
padding: 3px;
font-size: 0.8em;
}
#scrollcell {
width: 50px;
height: 50px;
overflow: auto;
}
I have an html table that contains a cell will a lot of data (maybe 200 lines).
Rather than requiring my page to scroll, I want my cell in the table to scroll.
I understand that I need a div
block to do this. I defined a div block in my
css file but it is not taking.
How do I fix the height of my cell and give my data a scrollbar?
--------html table-----------
<table class="cmain">
<tr>
<td> TOP LEFT CELL <p>
<table> <tr> <td> A sub-table goes here </td> </tr> </table>
</td>
<td> TOP RIGHT CELL <p>
<p> A PHOTO GOES HERE.
<p> PHOTO: {{ form.image }}
</td>
<td rowspan="2" valign="top" >
THIS IS THE CELL THAT NEEDS THE SCROLL BAR. <div id="scrollcell">
SCROLLER CELL <hr>
<p> {% for customer in customer_list %}
<p> {{ customer }} </p>
{% endfor %}
</div>
</td>
</tr>
<tr>
<td> Another Sub-table goes here.
<table> <tr> <td> A sub-table goes here </td> </tr> </table>
</td>
<td> A NOTES FORM FIELD GOES HERE <p>
{{ form.notes }} </td>
</tr>
</table> <!-- end of CMAIN table -->
--------css -----------
table, th, td {
border: 1px solid white;
}
table.cmain {
border: 1px solid blue;
}
table.cmain td {
border: 1px solid blue;
font-weight: bold;
/*width: 300;*/
padding: 3px;
font-size: 0.8em;
}
#scrollcell {
width: 50px;
height: 50px;
overflow: auto;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不久前回答了这样的问题,看看答案 这里和演示这里。
编辑
在此处发布代码以供其他海报将来参考:
HTML
CSS
如果您希望显示垂直和水平滚动条,只需替换
对于
和.inner-table
类,overflow-x:scroll;overflow:scroll
。I answered a question like this a while back, take a look at the answer here and the demo here.
EDIT
Posting code here for future reference for other posters:
HTML
CSS
If you wish to make the vertical and horizontal scrollbars appear just replace
overflow-x:scroll;
withoverflow:scroll
for the.inner-table
class.最简单的解决方案是将表格放入 iframe 中。否则,您可以使用 javascript 或
overflow
。The easiest solution would be to put the table into an iframe. Otherwise you can use either javascript or
overflow
.给这个 td 一个绝对高度和 100% 宽度/高度给 div
就像
和
give this td an absolute height and 100% width/height to the div
like
and