然后将页脚粘贴到页面底部而不滚动

时间:2016-01-15 14:37:43

标签: html css twitter-bootstrap sticky-footer

我在css-tricks.com上发现了一个教程,用于将页脚粘贴到屏幕/页面的底部并且效果很好,唯一的问题是,它会导致在页脚之后发生滚动。它轻微但很烦人。

继承人我的HTML:

<div class="container content">
  <div class="row">
    content
  </div>
</div>

<div class="container site-footer">
  <div class="row">
    <div class="col-md-7 col-md-offset-1">
      <h3 class ="footer-content"></h3><br><span class="text-muted">Version {{ TAG }}</span>
    </div>
  </div>  
</div>

以及我的css:

html, body {
height: 100%;
}
.content {
  min-height: 100%;
  /* equal to footer height */
  margin-bottom: -142px;
}
.content:after {
  content: "";
  display: block;
}
.site-footer, .content:after {
  height: 142px;
  min-width: 100%;
}
.site-footer {
  background: orange;
  padding: 0px;
  margin: 0px;
}

我正在使用Bootstrap 3以及

2 个答案:

答案 0 :(得分:0)

使用这些行重置CSS ,它将起作用:

/* 
   http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

答案 1 :(得分:0)

我在这里为你做了一个jsfiddle。这是使用你的标记,我重新编写CSS

    * {
    margin: 0;
}
html, body {
    height: 100%;
}
.content {
    min-height: 100%;
    margin: 0 auto -142px;
}
.site-footer {
    height: 142px;
  background:orange;
}

JSFiddle