调整窗口大小时表格滚动条消失
我为电子商务网站的后台制作了一张桌子。表格内容 (tbody) 具有固定高度,并且可以通过右侧的滚动条滚动,如下图所示:http://img690.imageshack.us/img690/6483/screenshot20110917at819.png
问题是,如果我调整浏览器窗口的大小,此表格滚动条就会消失: http://img26.imageshack.us/img26/4919/screenshot20110917at820.png
我知道这应该是正常行为,但我的客户坚持保留表格滚动条,即使在调整大小时也是如此窗户。有没有办法实现这种行为?
这是供参考的css:(表体的类是scrollContent)
/* define height and width of scrollable area. Add 16px to width for scrollbar */
div.tableContainer {
clear: both;
overflow: auto;
width: 100%;
}
/* set table header to a fixed position. WinIE 6.x only */
/* In WinIE 6.x, any element with a position property set to relative and is a child of */
/* an element that has an overflow property set, the relative value translates into fixed. */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
position: relative
}
/* set THEAD element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
html>body thead.fixedHeader tr {
display: block;
width: 100%
}
/* define the table content to be scrollable */
/* set TBODY element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto */
html>body tbody.scrollContent {
display: block;
overflow-y: auto;
overflow-x: hidden;
width: 100%;
}
I made a table for the back-office of an e-commerce site. The table content (tbody) has a fixed height and it is scrollable through a scrollbar on the right-hand side as depicted in this picture: http://img690.imageshack.us/img690/6483/screenshot20110917at819.png
The problem is that if I resize the browser window, this table scrollbar diseappears: http://img26.imageshack.us/img26/4919/screenshot20110917at820.png
I know this is supposed to be normal behavior, but my customer insists to keep the table scrollbar even when resizing the window. Is there a way to implement this behavior?
Here is the css for reference: (the table body's class is scrollContent)
/* define height and width of scrollable area. Add 16px to width for scrollbar */
div.tableContainer {
clear: both;
overflow: auto;
width: 100%;
}
/* set table header to a fixed position. WinIE 6.x only */
/* In WinIE 6.x, any element with a position property set to relative and is a child of */
/* an element that has an overflow property set, the relative value translates into fixed. */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
position: relative
}
/* set THEAD element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
html>body thead.fixedHeader tr {
display: block;
width: 100%
}
/* define the table content to be scrollable */
/* set TBODY element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto */
html>body tbody.scrollContent {
display: block;
overflow-y: auto;
overflow-x: hidden;
width: 100%;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,如果更改overflow-x:scroll或auto应该可以解决问题。由于它是隐藏的,他们无法访问滚动条,这可能是他们的抱怨。
另一种选择是运行 JavaScript 或 jquery,检查屏幕分辨率,然后用不同的表格替换表格或用较小的图像替换图像。这将允许表格缩小大小,以便它可以显示在非最大化窗口中。
/---- 编辑 ----/
检查窗口调整大小(您也不必在窗口上执行此操作,您可以在元素上执行此操作,但窗口将使您更准确地了解它们是否调整了其大小窗户。
Actually you if you change the overflow-x: scroll or auto should resolve the problem. Since it's hidden they can't access the scroll bar which is probably their complaint.
The other option would be to run a javascript or jquery that would check for screen resolution and then replace the table with a different table or replace the images with smaller images. This would allow the table to resize down so that it could display in the non-maximized window.
/---- EDIT ----/
Check window resize (you also don't have to do this on the window you can do it on an element but the window will give you a more accurate read on whether they have resized their window.
将 CSS 的溢出行为更改为始终显示,如下所示:
Change the oversflow behavior from CSS to always display, like so:
最终的代码如下,供稍后访问此页面的人参考:
For reference to those who will visit this page later, here is the final code: