表格滚动条在调整窗口大小时消失

时间:2011-09-16 23:32:50

标签: css scroll resize css-tables

我为电子商务网站的后台制作了一张桌子。表格内容(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%;
}

3 个答案:

答案 0 :(得分:1)

实际上,如果您更改overflow-x:scroll或auto应该可以解决问题。由于它是隐藏的,他们无法访问滚动条,这可能是他们的抱怨。

另一种选择是运行javascript或jquery来检查屏幕分辨率,然后用不同的表替换表或用较小的图像替换图像。这将允许表调整大小,以便它可以显示在非最大化窗口中。

/ ----编辑---- /

检查窗口调整大小(您也不必在窗口上执行此操作,您可以在元素上执行此操作,但窗口将为您提供有关他们是否已调整窗口大小的更准确读数。

var timerID = 0,
var winWidth = $(window).width(),
var winHeight = $(window).height();

$(document).ready(function()
{
    $(window).resize(function()
    {
        var winNewWidth = $(window).width(),
            winNewHeight = $(window).height();
        if(winWidth != winNewWidth || winHeight != winNewHeight)
        {
            window.clearTimeout(timerID);
            timerID = window.setTimeout(function()
            {
                // do something here
            },100)
        }
        winWidth = winNewWidth;
        winHeight = winNewHeight
    });
});

答案 1 :(得分:0)

将过流行为从CSS更改为始终显示,如下所示:

html>body tbody.scrollContent {
    display: block;
    overflow-y: scroll; //this will make sure to always display the scrollbar, whether it's active (available for scrolling) or not.
    overflow-x: hidden;
    width: 100%;
}

答案 2 :(得分:0)

有关稍后将访问此页面的人员的参考,以下是最终代码:

var winWidth = $(window).width();
var winHeight = $(window).height();
var winWidthDiff = 0;
var winHeightDiff = 0;
$i('scrollContent').style.maxWidth= ((winWidth-16)+"px");
$(window).resize(function(){
        var winNewWidth = $(window).width();
        var winNewHeight = $(window).height();
        winWidthDiff = winNewWidth - winWidth;
        winHeightDiff = winNewHeight - winHeight;
        winWidth = winNewWidth;
        winHeight = winNewHeight;
        scrollWidth = scrollWidth + winWidthDiff;
        scrollHeight = scrollHeight + winHeightDiff;
        $i('scrollContent').style.maxWidth= ((winWidth-16)+"px");
});