Log in |

CSS粘性底部

2007年07月13日 PM 51:10 | 作者:愆伏

原文:A CSS sticky footer
作者:Ryan Fait

我E文不好,不过代码看的懂
该文实现粘性居底的核心方法,就是负margin
先用一个容器wrapper包住除footer以外的内容
将wrapper的高度设置为100%,再用负的margin空出footer高度
如此实际wrapper的高度应等于100%-footer.height
效果达成

作者在HTML中加了一个和footer一样高度的push容器
没理解什么意思,可能是用来hack的。谁知道的话,我们探讨一下

把代码贴上

HTML:

  1. <html>
  2.    <head>
  3.   <link rel="stylesheet" href="layout.css" ... />
  4.   </head>
  5.    <body>
  6.    <div class="wrapper">
  7.    <p>Your website content here.</p>
  8.    <div class="push"></div>
  9.    </div>
  10.   <div class="footer">
  11.   <p>Copyright (c) 2008</p>
  12.   </div>
  13.   </body>
  14.   </html>

:

  1. * {
  2. margin: 0;
  3. }
  4. html, body {
  5. height: 100%;
  6. }
  7. .wrapper {
  8. min-height: 100%;
  9. height: auto !important;
  10. height: 100%;margin: 0 auto -4em; /* the bottom margin is the negative value of the footer&#39;s height */
  11. }
  12. .footer, .push {
  13. height: 4em; /* .push must be the same height as .footer */
  14. }

Related posts

评论(1 Comment)

  1. 这个方案比reallazy那个更好。

    [Reply]

发表评论

*必填

*必填 (不会被公开)