tyhenry
tyhenry

Reputation: 184

How to make content div full height when using padding on wrapper?

I know similar questions have been asked numerous times, but I've tried a number of answers and none seem to work for my situation. I've found a lot of solutions for sticky footers, but that's not exactly what I'm looking for, or maybe I haven't figured out how to use correctly for my situation:

Sticky footer doesn't work in this situation because the sticky footer just covers the content (the content itself is still 100% height). I basically want the content to be min-height 100% - minus the 50px header and 50px footer.

Is there any css solution to this without using a javascript hack or calc()? I would be willing to have the header + footer not be fix positioned - but I want to keep the box-shadow on the content div (i.e. 50px from top and bottom of the page).

JSFiddle: https://jsfiddle.net/tyhenry/n9rpbj3m/5/

HTML:

<div id="nav">
    <div id="header">
        header
    </div>
    <div id="left-side">
        left sidebar
    </div>
    <div id="right-side">
        right sidebar
    </div>
    <div id="footer">
        footer
    </div>
</div>
<div id="page-layer">

    <div class="page">
        content<br>
        content<br>
        content<br>
    </div>
</div>

CSS:

* {
    box-sizing: border-box;
}

html, body{
    background-color: #eeffff;
    text-align: center;
    margin: 0;
    padding: 0;
    height: 100%;
}

#header {
    position: fixed;
    top:0;
    left:0;
    width: 100%;
    height: 50px;
    background-color: #ddd;
}

#left-side {
    background-color: #bbb;
    position: fixed;
    left: 0;
    top: 50px;
    width: 50px;
    height: 100%;
}

#right-side {
    background-color: #bbb;
    position: fixed;
    right: 0;
    top: 50px;
    width: 50px;
    height: 100%;
    overflow: hidden;
}

#footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50px;
    background-color: #aaa;
}

#page-layer{
    position:relative;
    padding: 50px 0 50px 0;
    margin: 0 50px 0 50px;
    min-height: 100%;
}

.page {
    background-color: #fff;
    box-shadow: 0px 1px 20px 0px rgba(0, 0, 0, 0.8);
    width:100%;
}

Upvotes: 0

Views: 725

Answers (3)

harshitpthk
harshitpthk

Reputation: 4136

Try this updated fiddle https://jsfiddle.net/n9rpbj3m/6/

#page-layer{

position:absolute;
top:50px;
left:50px;
right:50px;
bottom:50px;
}

.page {
position:relative;
background-color: #fff;
box-shadow: 0px 1px 20px 0px rgba(0, 0, 0, 0.8);
height:auto;
min-height: 100%;
width:100%;
}

Upvotes: 0

cocoa
cocoa

Reputation: 3921

If you change the display property to flex it fills the whole (height between header and footer) and adjusts when you resize.

#page-layout {
  display: flex;
}

Upvotes: 0

user4431269
user4431269

Reputation:

give this you the desirable outcome ? can i use viewport units

add:
    .page {
        min-height: 100vh; /*min-height not height :)*/
    }

Upvotes: 0

Related Questions