【问题标题】:Stick footer to bottom of page without scroll afterwards将页脚粘贴到页面底部而不滚动
【发布时间】:2016-04-21 04:29:27
【问题描述】:

我在 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

【问题讨论】:

  • “导致页脚后出现滚动”是什么意思?也许你可以分享一个截图?
  • 这是我一直在尝试弄清楚的 codepen 画布,以便您自己查看codepen.io/Shredivan/pen/MKEyGm
  • 添加一个 css 重置/规范化并删除页脚标题上的所有边距。通常在这种情况下,问题是 HTML/body 元素和/或顶部或底部附近的标题元素上的填充或边距。
  • 我在 codepen 中使用 normalize.css 文件设置了文件,我尝试从中删除边距和填充,仍然没有运气
  • 我将它添加到了您的笔的顶部并且效果很好:*{ margin:0px; }

标签: html css twitter-bootstrap sticky-footer


【解决方案1】:

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

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

JSFiddle

【讨论】:

  • 感谢您的帮助,它在您的 JSFiddle 和我的 codepen 设置中运行良好,但是当我将它重新集成到本地计算机上的引导设置中时,它仍然具有滚动。可能是我的样式表中的其他东西影响了它。
  • 就像另一个答案所说,可能是引导程序中的一些默认值覆盖了初始 * 设置,因此它对 html/body 应用填充或边距
【解决方案2】:

只需使用这些行重置您的 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;
}

【讨论】:

    猜你喜欢
    • 2014-11-09
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 2013-07-27
    • 1970-01-01
    相关资源
    最近更新 更多