gpt4 book ai didi

html - 使用 Google MDL 将页脚保持在页面底部

转载 作者:技术小花猫 更新时间:2023-10-29 12:17:22 25 4
gpt4 key购买 nike

据我所知,这不是一个重复的问题,因为它与关于该主题的其他问题有点不同。

我使用的是 Google 的 Material Design Lite,页脚无法正确位于页面底部。

我见过使用这个技巧的不同修复

<div class="content">
<div class="header"></div>
<div class="body"></div>
<div class="footer"></div>
</div>

我试过用这个方法

#footer {
bottom: 0;
width: 100%;
position: absolute; (or fixed)
}

第一个选项不起作用,因为 Material Design Lite 实际上使用了页脚标签。老实说,我真的不想这样做,因为这对我来说有点草率。

页脚的 CSS 方法几乎可以工作,但存在一些问题。使用 position: absolute; 时,页脚并不总是位于页面底部,有时会覆盖内容。当我尝试 fixed 时,页脚始终保持在页面底部,但当页面有足够的内容滚动时,它会停留在屏幕底部并覆盖内容。 fixedabsolute 都会将页脚保持在屏幕底部而不是页面底部,这意味着当有足够的内容可以滚动时,页脚会覆盖页面边缘的内容屏幕。

fixed 的行为可以在 100% 的时间内重现,但是对于 absolute 我还没有弄清楚是什么原因导致它有时工作而不是其他。

这是我的页脚代码

<footer class="mdl-mini-footer">
<div class="mdl-mini-footer--left-section">
<button class="mdl-mini-footer--social-btn social-btn social-btn__twitter">
<span class="visuallyhidden">Twitter</span>
</button>
<button class="mdl-mini-footer--social-btn social-btn social-btn__blogger">
<span class="visuallyhidden">Facebook</span>
</button>
<button class="mdl-mini-footer--social-btn social-btn social-btn__gplus">
<span class="visuallyhidden">Google Plus</span>
</button>
</div>
<div class="mdl-mini-footer--right-section">
<button class="mdl-mini-footer--social-btn social-btn__share">
<i class="material-icons" role="presentation">share</i>
<span class="visuallyhidden">share</span>
</button>
</div>
</footer>`

有没有其他人遇到过这个问题或对解决方案有任何想法?

编辑以添加更多信息:

问题不在于 bodyhtml 的高度,它们都是 100%。

完整布局代码

<body>
<div class="site mdl-layout mdl-js-layout">
<header class="mdl-layout__header mdl-layout__header--waterfall">
<div class="mdl-layout__header-row">
<!-- Header Content Here -->
</div>
</header>
<div class="mdl-layout__drawer">
<!-- Drawer Content -->
</div>
<main class="mdl-layout__content">
<!-- View Content Here -->
</main>
<footer class="mdl-mini-footer">
<!-- Footer Content -->
</footer>
<div class="mdl-layout__obfuscator"></div>
</div>
</body>

最佳答案

我设法做到了:

1。没有瀑布头

  1. 将页脚元素移到主要元素之外
  2. .mdl-layout__content元素的样式设置为"flex: 1 0 auto"

示例:

<body>
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
...
</header>
<main class="mdl-layout__content" style="flex: 1 0 auto;">
...
</main>
<footer class="mdl-mega-footer">
...
</footer>
</div>
</body>

2。带瀑布头

  1. 只需将页脚元素移到主元素之外

示例:

  <body>
<div class="site mdl-layout mdl-js-layout">
<header class="mdl-layout__header mdl-layout__header--waterfall">
<div class="mdl-layout__header-row">
<!-- Header Content Here -->
</div>
</header>
<div class="mdl-layout__drawer">
<!-- Drawer Content -->
</div>
<main class="mdl-layout__content">
<!-- Main Content -->
</main>
<footer class="mdl-mini-footer">
<!-- Footer Content -->
</footer>
</div>
</body>

测试:

关于html - 使用 Google MDL 将页脚保持在页面底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32953378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com