1

If possible, how can I use CSS only to vertically center a div between fixed margin at the top and bottom? The margin is to accommodate a header and a footer.

http://jsfiddle.net/u8PhW/6/

<div id="header" style="position: fixed; height: 200px; background-color: orange;"></div>
<div class="viewport" style="overflow: hidden">
    <div class="page">
        <div class="content">Vertically Aligned Section 1</div>
    </div>
    <div class="page">
        <div class="content">Vertically Aligned Section 2</div>
    </div>
</div>
<div id="footer" style="position: fixed; height: 50px; bottom: 0px; background-color: gray;"></div>

The idea of this HTML is that there is a fixed header and footer and the content should be centered between these 2 divs. Additionally, the javascript allows the just to "jump" to different pages. The content within these page should be centered between the header and footer.

Jake
  • 11,273
  • 21
  • 90
  • 147

1 Answers1

1

Demo

css

div.content {
    position: fixed;
    background-color: red;
    top:200px;
    bottom:50px;
    margin:auto;
    height: 200px;
}
4dgaurav
  • 11,360
  • 4
  • 32
  • 59
  • +1 OK, that works based on my question. Looks like I have to improve my question to be more specific. – Jake Apr 28 '14 at 08:15