如何使可调整大小的div内的表可滚动,正常运行

时间:2013-11-12 17:30:28

标签: html css scroll html-table jquery-ui-resizable

我有一个可调整大小且可移动的div使用JQuery UI。我想在里面有一张垂直滚动的桌子。尝试将表高度设置为100%基本上什么都不做,并且顶部和底部为0的绝对定位也不起作用。我试图把一个单独的div作为一个容器,这让我比任何东西更接近,但它仍然表现不正常。

这是小提琴:http://jsfiddle.net/scottbeeson/KrP7v/1/

以下是相关的CSS:

table {
    border-collapse: collapse;
    width: 100%; height: 100%;
}
#tableContainer {
    height: 100%; width: 100%;
    overflow-x: hidden;
    overflow-y: scroll;
}

基本的HTML布局:

<div id="window">
    <div id="header">Draggable Header</div>
    <div id="tableContainer">
    <table>
        <thead>
            <tr>
                <td>Column 1</td>
                <td>Column 2</td>
            </tr>
        </thead>
        <tbody>
            ...
        </tbody>
    </table>
    </div>
</div>

2 个答案:

答案 0 :(得分:1)

我认为这就是你想要的。

http://jsfiddle.net/KrP7v/12/

#window {
    width: 500px;
    height: 400px;
    min-width: 100px;
    min-height: 100px;
    border-bottom: 1px solid gray;
}
#header {
    height: 25px;
    line-height: 25px;
    background-color: gray;
    color: white;
    text-align: center;
}
table {
    min-height: 300px;
    height: 100%;
    width: 100%;
    border-collapse: collapse;
}
#tableContainer {
    position: absolute;
    top: 25px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    margin: 0;
    padding: 0;
    overflow: auto;
}
td {
    padding: 5px;
    margin: 0px;
    border: 1px solid gray;
}
tr:last-child td {
    border-bottom: none;
}

答案 1 :(得分:0)

以下是您可以做的事情:

http://jsfiddle.net/KrP7v/4/

#window {
  width: 400px; 
  border: 1px solid green;
  overflow-x: scroll;
  overflow-y: scroll;
}
相关问题