Published in: HTML
URL: http://veerle.duoh.com/index.php/blog/comments/designing_a_css_based_template_part_vii/
Footer moves dynamically when resizing browser. Behaviour of movement is in the Javascript.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style type="text/css"> body { margin: 0; padding: 0; text-align: center; } .clear { clear: both; } #container { margin: 0px auto; text-align: left; width: 692px; border: 1px solid black; } #content { width: 479px; float: left; padding: 15px 0 10px 20px; } #footer { margin: 0px auto; position: relative; background-color: #717F51; border-top: 9px solid #F7F7F6; width: 692px; padding: 5px 0; clear: both; } </style> <script type="text/javascript"> <!-- function getWindowHeight() { var windowHeight = 0; if (typeof(window.innerHeight) == 'number') { windowHeight = window.innerHeight; } else { if (document.documentElement && document.documentElement.clientHeight) { windowHeight = document.documentElement.clientHeight; } else { if (document.body && document.body.clientHeight) { windowHeight = document.body.clientHeight; } } } return windowHeight; } function setFooter() { if (document.getElementById) { var windowHeight = getWindowHeight(); if (windowHeight > 0) { var contentHeight = document.getElementById('container').offsetHeight; var footerElement = document.getElementById('footer'); var footerHeight = footerElement.offsetHeight; if (windowHeight - (contentHeight + footerHeight) >= 0) { footerElement.style.position = 'relative'; footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px'; } else { footerElement.style.position = 'static'; } } } } window.onload = function() { setFooter(); } window.onresize = function() { setFooter(); } --> </script> </head> <body> <div id="container"> <div id="content"> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p> </div> <!-- * Needed because container is floated left. If you don't clear footer won't show in Safari * Only needed if floating http://veerle.duoh.com/index.php/blog/comments/fun_with_floats/ --> </div> <!-- Begin Footer --> <div id="footer"> </div> <!-- End Footer --> </body> </html>
You need to login to post a comment.
