Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed header, fixed footer dynamic content

I'm struggling with my dynamic content. So let me explain in a picture:

enter image description here

So my html looks like:

<div id="header"> ... </div>

<div id="container">
    <div class="block"> ... </div>
    <div class="block"> ... </div>
    <div class="block"> ... </div>
    <div class="block"> ... </div>
</div>

<div id="footer"> ... </div>

My question: How can I get my container be fluid and the header and footer be fixed? The blocks in the container are set on 50% height and width, so only the container has to be the 100% height (- the fixed header and footer).

like image 242
Haidy Avatar asked Dec 16 '22 05:12

Haidy


1 Answers

You can do this with box-sizing property.

Like so:

FIDDLE

(the example I use here assumes a header of 64px height and footer of 30px height)

Markup

<header>header</header>
 <div class="container">
     <div id="content">
         <div class="block">block1</div><!--
         --><div class="block">block2</div><!--
         --><div class="block">block3</div><!--
         --><div class="block">block4</div>
    </div>    
</div>
<footer>footer</footer>

CSS

html,body
{
    height: 100%;
}
header,footer,div
{
   width: 100%; 
}
.container
{
    height: 100%;
    background: pink;
    margin: -64px 0 -30px;
    padding: 64px 0 30px;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
#content {
    overflow:auto;
    height:100%;
}
.block
{
    width: 50%;
    height: 50%;
    display: inline-block;
    border: 1px solid yellow;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    text-align: center;
}
header
{
    height: 64px;
    background: purple;
    position: relative;
    z-index:1;
}
footer
{
    height: 30px;
    background: gray;
    position: relative;
    z-index:1;
}
like image 148
Danield Avatar answered Jan 02 '23 10:01

Danield