HTML:
<body>
<header id="header">
<div class="inner responsive">
<h2>Dit is de header</h2>
</div>
</header>
<section id="main">
<div id="content" class="responsive">
<div class="inner">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</section>
<footer id="footer">
<div class="inner responsive">
<h2>Dit is de footer</h2>
</div>
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="main.js"></script>
</body>
CSS:
/* simpele reset */
html, body, body * {
margin: 0; padding: 0; font-family: verdana, sans-serif;
}
header, nav, section, footer {
display: block;
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
/* sticky (noscroll, main en content nodig in javascript) */
.noscroll {
overflow: hidden;
overflow-y: hidden;
}
#header, #main, #content, #footer {
margin: 0;
padding: 0;
}
/* responsive */
.responsive {
width: auto;
margin: 0 auto !important;
}
@media (min-width: 768px) {
.responsive { width: 750px; }
}
@media (min-width: 992px) {
.responsive { width: 970px; }
}
@media (min-width: 1200px) {
.responsive { width: 1170px; }
}
/* achtergrond (geen margin, padding, border) */
#header { background: #9af; }
#main { background: #af9; }
#content { background: #fff; }
#footer { background: #f9a; }
/* opmaak (op inner of elementen in inner) */
.inner {
padding: 15px;
}
#content .inner {
color: #33a;
}
JS (main.js):
$(document).ready(function(){
var dheight = $('body').height(),
mheight = $('#main').height(),
wheight = $(window).height(),
cheight = wheight - dheight + mheight;
if (wheight > dheight){
$('#main,#content').height(cheight);
}
$(window).resize(function(){
wheight = $(window).height();
noscroll();
changepush();
});
function noscroll(){
if (wheight > dheight) {
$('html').addClass('noscroll');
} else if (wheight <= dheight) {
$('html').removeClass('noscroll');
} else {
}
}
function changepush(){
if (wheight > dheight) {
$('#main,#content').height(wheight-dheight+mheight);
}
}
});