【发布时间】:2016-10-13 18:38:40
【问题描述】:
我正在尝试在 Material Design lite 框架中实现一个粘性页脚。我选择这样做using flexbox,因为 MDL 已经使用了它,而且它是我所知道的最灵活和无 hack 的方法。
main.main-layout {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.page-content {
/*min-height: 500px;*/
}
div.mdl-layout__container{
height:auto;
}
<html>
<head>
<link href="https://code.getmdl.io/1.2.1/material.indigo-pink.min.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<script src="https://code.getmdl.io/1.2.1/material.min.js"></script>
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--no-drawer-button">
<header class="mdl-layout__header mdl-layout__header--waterfall mdl-layout__header--waterfall-hide-top" id="djpsych-header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row" id="djpsych-header__top-row">
<div class="mdl-layout-spacer"></div>
<span class="mdl-layout__title"> Title of the site </span>
<div class="mdl-layout-spacer"></div>
</div>
<div class="mdl-layout__header-row">
<div class="mdl-layout-spacer"></div>
some kind of navbar element
<div class="mdl-layout-spacer"></div>
<a id='top'></a>
</div>
</header>
<main class="mdl-layout__content main-layout">
<div class="page-content">
<p>This is the content of the page!</p>
<p>This is the content of the page!</p>
<p>This is the content of the page!</p>
<p>This is the content of the page!</p>
<p>This is the content of the page!</p>
<p>This is the content of the page!</p>
<p>This is the content of the page!</p>
<p>This is the content of the page!</p>
</div>
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__middle-section">
<div class="mdl-logo">Title</div>
<ul class="mdl-mini-footer__link-list">
<li><a href="#">Help</a>
</li>
<li><a href="#">Privacy & Terms</a>
</li>
</ul>
</div>
</footer>
</main>
</div>
</body>
</html>
标题可能无法在小预览屏幕上呈现。您可以看到页脚的下半部分被截断。这仅在内容高于视口时才会发生,否则粘性页脚修复工作正常(尝试更改 .page-content 规则的 min-height)。我注意到在这些情况下,页脚内容的高度变为 0,但是当 <div class="page-content"> 的内容没有填满视口时,页脚实际上有一个高度。这是一个错误吗?
请注意,页脚的 html 直接取自 MDL 文档。
【问题讨论】:
标签: html css flexbox material-design-lite