We Recommend

HTML: The Definitive Guide HTML: The Definitive Guide
They teach you that learning HTML is like learning any other language and that reading a book of rules can only take you so far. Readers begin writing what may be their first Web page just two pages into the book's second chapter. From there on, they provide a wide range of HTML coding to allow readers to learn from good examples. The book includes a handy "cheat sheet" of HTML codes for quick reference.


Posted By

indianocean on 06/29/07


Tagged

css javascript template html crossbrowser


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

joseluis
joomla


Template with footer fixed to viewport, working in Safari too


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.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title>Lorem ipsum dolor sit amet</title>
  7.  
  8. <style type="text/css">
  9.  
  10. body {
  11. margin: 0;
  12. padding: 0;
  13. text-align: center;
  14. }
  15.  
  16. .clear {
  17. clear: both;
  18. }
  19.  
  20. #container {
  21. margin: 0px auto;
  22. text-align: left;
  23. width: 692px;
  24. border: 1px solid black;
  25. }
  26.  
  27. #content {
  28. width: 479px;
  29. float: left;
  30. padding: 15px 0 10px 20px;
  31. }
  32.  
  33. #footer {
  34. margin: 0px auto;
  35. position: relative;
  36. background-color: #717F51;
  37. border-top: 9px solid #F7F7F6;
  38. width: 692px;
  39. padding: 5px 0;
  40. clear: both;
  41. }
  42.  
  43. <script type="text/javascript">
  44. <!--
  45. function getWindowHeight() {
  46. var windowHeight = 0;
  47. if (typeof(window.innerHeight) == 'number') {
  48. windowHeight = window.innerHeight;
  49. }
  50. else {
  51. if (document.documentElement && document.documentElement.clientHeight) {
  52. windowHeight = document.documentElement.clientHeight;
  53. }
  54. else {
  55. if (document.body && document.body.clientHeight) {
  56. windowHeight = document.body.clientHeight;
  57. }
  58. }
  59. }
  60. return windowHeight;
  61. }
  62. function setFooter() {
  63. if (document.getElementById) {
  64. var windowHeight = getWindowHeight();
  65. if (windowHeight > 0) {
  66. var contentHeight = document.getElementById('container').offsetHeight;
  67. var footerElement = document.getElementById('footer');
  68. var footerHeight = footerElement.offsetHeight;
  69. if (windowHeight - (contentHeight + footerHeight) >= 0) {
  70. footerElement.style.position = 'relative';
  71. footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
  72. }
  73. else {
  74. footerElement.style.position = 'static';
  75. }
  76. }
  77. }
  78. }
  79. window.onload = function() {
  80. setFooter();
  81. }
  82. window.onresize = function() {
  83. setFooter();
  84. }
  85. -->
  86. </head>
  87.  
  88. <div id="container">
  89. <div id="content">
  90. <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>
  91. </div>
  92.  
  93. <!--
  94. * Needed because container is floated left. If you don't clear footer won't show in Safari
  95. * Only needed if floating
  96. http://veerle.duoh.com/index.php/blog/comments/fun_with_floats/ -->
  97. <div class="clear">&nbsp;</div>
  98. </div>
  99.  
  100. <!-- Begin Footer -->
  101. <div id="footer">
  102. <h2>Subliminial Footer Message</h2>
  103. </div>
  104. <!-- End Footer -->
  105.  
  106. </body>
  107. </html>

Report this snippet 

You need to login to post a comment.