0

我已经尝试了很多方法来使用 css calc 和表格布局来获取滚动条。下面是我的小提琴。任何帮助是极大的赞赏。

JSFIDDLE:http: //jsfiddle.net/y3U8F/124/

在这里,我想要滚动条#content

HTML:

<div class="displayTable">
<div class="displayTableCell">
<div id="content">
      body content<br>body content<br> ...
</div>
<footer>copyright etc</footer>

</div>
</div>

CSS:

html, body { 
   height: 100%;
}
#content {
    height: -webkit-calc(100% - 50px); 
    background-color: yellow;
    overflow:auto
}
footer {
    height: 50px;
    background-color: grey;
}
.displayTable{display:table;table-layout:fixed;width:100%}
.displayTableCell{display:table-cell}
4

1 回答 1

1

#content的高度是根据其父级计算的,而不是body页面的。

一个简单的解决方法是指定 和 的table高度table-cell

<div class="display:table;table-layout:fixed"> <-- height:100% / fixed height
    <div class="display:table-cell">           <-- height:100%
         <div id="content"> </div>             <-- height:calc(height:100% - 50px)
         <footer> </footer>                    <-- height:50px;
    </div>
</div>

小提琴:http: //jsfiddle.net/y3U8F/126/

于 2015-12-11T10:59:40.213 回答