【问题标题】:Why is my footer being pushed up when viewed on mobile?为什么在移动设备上查看时我的页脚被向上推?
【发布时间】:2019-03-27 20:05:42
【问题描述】:

我有一个响应式页脚,直到我在移动设备上查看。在移动设备上查看时,页脚被推到容器/div 后面,同时在页脚下方留下一个小的空白区域。

我尝试使用各种页脚、div、容器等。我目前正在使用 flex,页脚在桌面/平板电脑上工作正常。想知道我是否需要移动设备的媒体查询..

.footer {
    display: flex;
    justify-content: center;
    height: 300px;
    width: 100%;
    background-color: orange;
    margin-top: 300px;
}
 <div class="footer">
  <p>
    testing to see if can move to bottom
  </p>
</div>  

只是希望有一个带有社交媒体图标的漂亮页脚,它保持在底部并在移动设备上响应。

【问题讨论】:

  • 默认情况下,段落元素的下边距不为零。您需要覆盖它。
  • .footer 上添加填充。即使是 1px 也会处理溢出的段落边距。
  • 添加一个复制问题的 sn-p - 当前的 sn-p 不这样做.. 我们只能猜测:)

标签: html css


【解决方案1】:

如果您将主体边距和内边距重置为 0 像素,可能会有所帮助。例如,在 Chrome 中,body 标签默认有 8px 的边距。

在实现您自己的样式之前尝试实现一个标准的重置 CSS,以防止浏览器默认更改您的布局并获得更统一的元素呈现。

body {
   background-color: black;
   padding:0px;
   margin: 0px;
}
.footer {
    display: flex;
    justify-content: center;
    height: 300px;
    width: 100%;
    background-color: orange;
    margin-top: 300px;
}
<div class="footer">
  <p>
    testing to see if can move to bottom
  </p>
</div>

重置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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    相关资源
    最近更新 更多