利用CSS使footer固定在页面底部的实例代码


1. HTML基本结构

XML/HTML Code复制内容到剪贴板
  1. <!DOCTYPEhtml>  
  2.   
  3. <htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml">  
  4.   
  5. <headrunatheadrunat="server">  
  6.   
  7.     <title>layout</title>  
  8.   
  9. </head>  
  10.   
  11. <body>  
  12.   
  13.     <divclassdivclass="header">  
  14.   
  15.         <h1>head of your website.</h1>  
  16.   
  17.     </div>  
  18.   
  19.     <divclassdivclass="wrapper">  
  20.   
  21.         <divclassdivclass="content">  
  22.   
  23.             <h2>Your website content here.</h2>  
  24.   
  25.             <scripttypescripttype="text/javascript">  
  26.   
  27.                 for(var i = 0; i<100;i++){   
  28.   
  29.                     document.write(i + "<br />");   
  30.   
  31.                 }   
  32.   
  33.             </script>  
  34.   
  35.         </div>  
  36.   
  37.         <divclassdivclass="clear"><!-- 必不可少 --></div>  
  38.   
  39.     </div>  
  40.   
  41.     <divclassdivclass="footer">  
  42.   
  43.         <div><h1>  
  44.   
  45.             Copyright (c) 2012</h1></div>  
  46.   
  47.     </div>  
  48.   
  49. </body>  
  50.   
  51. </html>  
  52.   

2. CSS样式

CSS Code复制内容到剪贴板
  1. <styletype="text/css">   
  2.   
  3.         *{   
  4.   
  5.             margin: 0;/* 把默认值都设为0 */  
  6.   
  7.         }   
  8.   
  9.         html, body   
  10.   
  11.         {   
  12.   
  13.             height: 100%;   
  14.   
  15.             width:85%;   
  16.   
  17.             margin:0auto;/* 居中 */  
  18.   
  19.         }   
  20.   
  21.            
  22.   
  23.         .header   
  24.   
  25.         {   
  26.   
  27.             height:100px;   
  28.   
  29.             background-color:Fuchsia;   
  30.   
  31.         }   
  32.   
  33.            
  34.   
  35.         .wrapper   
  36.   
  37.         {   
  38.   
  39.             min-height: 100%;/* IE6 hack*/  
  40.   
  41.             heightauto!important;/* height优先级 */  
  42.   
  43.             height: 100%;   
  44.   
  45.             margin: 0auto-4em;/* 负值必须等于footer的高度 */  
  46.   
  47.         }   
  48.   
  49.            
  50.   
  51.         .content  
  52.   
  53.         {   
  54.   
  55.             background-color:Silver;   
  56.   
  57.         }   
  58.   
  59.            
  60.   
  61.         .clear/* 清除浮动 */  
  62.   
  63.         {   
  64.   
  65.             height: 4em; /* clear的height必须和footer的值样高 */  
  66.   
  67.             clear:both;   
  68.   
  69.         }   
  70.   
  71.            
  72.   
  73.         .footer   
  74.   
  75.         {   
  76.   
  77.             height: 4em;   
  78.   
  79.             background-color:Aqua;   
  80.   
  81.         }   
  82.   
  83.     </style>   

以上这篇利用CSS使footer固定在页面底部的实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持phpstudy。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3