如果 div 延伸到视口底部下方,则添加滚动条
我的页面中有一个
,其中包含一个不同行数的 ,即不同的高度:
<html>
<head></head>
<body>
<div>
<table>
<tr>...
<tr>...
...
</table>
</div>
</body>
</html>
目前,如果表格内容很长足够了,div 延伸到页面底部(视图端口)下方。我想停止 div 延伸到页面底部下方,并添加滚动条。如果 div 高度固定,overflow:scroll
没有问题,我可以添加滚动条。但我希望 div 高度适合用户调整浏览器窗口大小的大小。
有什么想法如何实现这一目标?如果没有表格内容,我不关心或不需要 div 延伸到页面底部。最好是纯 css 解决方案,而不是使用 javascript 来固定 div 高度。
谢谢
I have a <div>
in my page which contains a <table>
of varying number of rows, i.e varying height:
<html>
<head></head>
<body>
<div>
<table>
<tr>...
<tr>...
...
</table>
</div>
</body>
</html>
At the moment if the table content is long enough, the div extends below the bottom of the page (view port). I want to stop the div extending below the bottom of the page, and add a scroll bar. I can add scroll bars if the div height is fixed no problem with overflow: scroll
. But I want the div height to fit to however the user has sized his browser window.
Any ideas how to achieve this? I do not care or need the div to extend to the bottom of the page if there is no table content. Preferably a pure css solution as opposed to using javascript to fix the div height.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个带有溢出自动和一些 100% 欺骗的包装器怎么样?即此的一些变体:
查看 jsFiddle 的演示。
How about a wrapper with overflow auto and some 100% trickery. I.e. some variant of this:
See a demonstration at jsFiddle.
CSS 类有一个漂亮的带有滚动的
Div
Css class to have a nice
Div
with scroll