【问题标题】:HTML/CSS Whitespace under footer页脚下的 HTML/CSS 空白
【发布时间】:2015-06-24 20:55:54
【问题描述】:

我遇到了页脚下方的空白问题。我在 Stack Overflow 上进行了搜索,似乎找不到适合我的答案,所以希望有人可以帮助我解决我的具体问题。

我注意到的事情:

  1. 我根本无法检查这个空白。我尝试使用开发工具检查所有内容,但它看起来不在 HTML 范围内。
  2. 这是一个 Rails 项目。我删除了<%= yield %> 标记以查看它是否是来自另一个页面/部分的空间,但删除<%= yield %> 标记后空间仍然存在。
  3. 我没有使用任何 Javascript 文件

application.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>DoINeedAJacket</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>
  <div class="wrapper">
    <%= yield %>
    <div class="push"></div>
  </div>
  <div class="footer">
    <ul>
      <%= link_to image_tag('facebook-1.png', size: '32x32'), '####' %>
      <%= link_to image_tag('twitter-1.png', size: '32x32'), '####' %>
      <%= link_to image_tag('linkedin-1.png', size: '32x32'), '####' %>
      <%= link_to image_tag('github-1.png', size: '32x32'), '####' %>
    </ul>
  </div>
</body>
</html>

application.css.scss

* {
  margin: 0;
}

html {
  height: 97%;
}
body {
  height: 100%;
}

.wrapper {
  min-height: 100%;
  height: auto !important;
  height: 100%;
  margin: 0 auto -3em;
}

.footer, .push {
  height: 3em;
  text-align: center;
  ul {
    padding: 0;
    margin-bottom: 0;
    img {
      margin: 0.5rem;
    }
  }
}

我将高度设置为 97% 的原因是我需要摆脱一些滚动空间。如果有更好的方法,请告诉我。

谢谢!

【问题讨论】:

    标签: html css ruby-on-rails sass


    【解决方案1】:

    这是没有页脚边距的 CSS(没有 SCSS,只有 CSS):

        * {
          margin: 0;
        }
        html, body { margin: 0; padding: 0; }
        html {
          height: 97%;
        }
        body {
          height: 100%;
        }
        .wrapper {
          min-height: 100%;
          height: auto !important;
          height: 100%;
          margin: 0 auto -3em;
        }
    
        .footer, .push {
          height: 3em;
          text-align: center;
        }
        .footer {
          position: absolute;
          width: 100%;
          bottom: 0;
          padding-bottom: .5rem;
        }
        .footer  ul, .push  ul {
            padding: 0;
            margin-bottom: 0;
          }
    
        .footer  ul img, .push  ul img {
          margin: 0.5rem;
        }
    

    【讨论】:

      【解决方案2】:

      position:relative; 添加到.wrapper

      还有position:absolute; bottom:0; 给你的footer

      【讨论】:

      • 虽然这确实会强制元素位于页面底部,但它并没有解释底部的空白区域是什么。或者至少底部仍然显示空白
      • 我认为空格是 html{ height:97%; }。实时链接会很有帮助。
      猜你喜欢
      • 2017-10-29
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多