CSS和HTML5:在页面底部放置一个<footer>?没有包装?

mat*_*att 14 html css html5 footer

这个古老的问题.我需要<footer>在页面底部放置一个元素.但是我没有包装div.

我确实有以下结构......

<body>
<header>
<section id="content">
<footer>
</body>
Run Code Online (Sandbox Code Playgroud)

如果内容不够高,是否有一种简单的方法将页脚推到底部?

Tra*_*Coy 17

来自这个问题,并认为我会发布我遇到的情况.对我来说似乎是理想的方式.

CSS:

html {
    position: relative;
    min-height: 100%;
}
body {
    margin: 0 0 100px; /* bottom = footer height */
}
footer {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 100px;
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

HTML5:

<!DOCTYPE html>
<head>
    <title></title>
</head>
<body>
    <nav></nav>
    <article>Lorem ipsum...</article>
    <footer></footer>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

所有功劳都归功于http://mystrd.at/modern-clean-css-sticky-footer/


Mar*_*c B 10

做到了position: fixed; bottom: 0, height: xxx吗?当然,如果页面实际超过窗口底部,它会重叠任何内容.也许有些JS可以检测"短"内容并设置适当的css.

  • 只需在内容中设置一个底部边距,该内容等于页脚的高度 (6认同)

Kar*_*arl 1

据我所知,这仍然是让页脚粘在页面底部的最佳方法:

http://www.themaninblue.com/experiment/footerStickAlt/