Ashwin
Ashwin

Reputation: 12411

Getting scroll using calc

I have tried many things to get scroll bar using css calc and table layout. Below is my fiddle. Any help is greatly appreciated.

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

Here, I want scrollbar for #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}

Upvotes: 1

Views: 7083

Answers (1)

Alexandru Severin
Alexandru Severin

Reputation: 6228

Your #content's height is calculated based on its parent, not the body of the page.

One easy fix is to specify the height for the table and the 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>

fiddle: http://jsfiddle.net/y3U8F/126/

Upvotes: 1

Related Questions