如何在页面的最底部放置一个div?

乔·莫拉诺(Joe Morano)

我有一个简单的div <div id="bottom"></div>,我想将其放置在页面的最底部。如果我做

position: absolute;
bottom: 0%;

然后将其自身放置在页面可见部分的底部,而不是实际底部。如果我愿意

position: relative;
bottom: 0%;

它只是停留在其默认位置。如何将其放在最底端?

4dgaurav

演示版

html

<div id="container">
    <div id="header">
        <!-- Header start -->
        <h1>How to keep footers at the bottom of the page (CSS demo)</h1>
        <!-- Header end -->
    </div>
    <div id="body">
        <!-- Body start -->
        <p>In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal.</p>
        <!-- Body end -->
    </div>
    <div id="footer">
        <!-- Footer start -->
        <p><strong>Footer</strong> (always at the bottom).</p>
        <!-- Footer end -->
    </div>
</div>

的CSS

html, body {
    margin:0;
    padding:0;
    height:100%;
}
#container {
    min-height:100%;
    position:relative;
}
#header {
    background:#ff0;
    padding:10px;
}
#body {
    padding:10px;
    padding-bottom:60px;
    /* Height of the footer */
}
#footer {
    position:absolute;
    bottom:0;
    width:100%;
    height:60px;
    /* Height of the footer */
    background:#6cf;
}
/* other non-essential CSS */
 #header p, #header h1 {
    margin:0;
    padding:10px 0 0 10px;
}
#footer p {
    margin:0;
    padding:10px;
}

注意:如果您的身体内容足够长,则页脚将在页面底部。如果内容足够短,它将停留在屏幕底部。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

同时在页面底部和中心放置一个 div

如何在另一个页面的底部导航栏中导航?

如何在不固定位置的情况下将文本放置在页面的最底部?

如何在div底部和图像下方放置一个按钮?

在屏幕底部放置一个div

在页面底部放置一个div,然后根据下面显示的div重新定位

如何在一个div内居中放置一个div,最简单的方法是什么?

如何在手机屏幕的最底部放置一个 Text/ListTile 小部件(在抽屉内)

CSS 在页面底部放置一个没有内容的 Div

如何在网站底部创建一个 div?

如何放置一个部分作为所有页面的背景?

如何在div的文本后面放置一个元素?

我如何根据他的 ID 放置一个指向另一个页面的超链接?

如何在另一个div下方放置一个div?

如何在一个div内居中放置一个div?

如何在另一个div的正下方放置一个div?

如何在另一个div前面放置一个div?

如何在可绘制对象的底部放置一个图像视图

如何在每个部分的底部中心放置一个箭头?

如何将文本放置在与另一个div浮动在一起的div的底部

如何将该div放置在页面底部

如何在中心垂直对齐两个div,在底部保持一个div?

从页面顶部到底部隐藏一个div

如何将一个div居中放置在底部,并在中间放置另一个可实现的居室?

如何将数字放置在乳胶页面的底部?

如何将此图像放置在页面的底部中心?

如何在flutter中创建一个始终粘在页面底部的按钮?

更新整个页面的一个div的问题

如何获得一个div来填充整个页面的宽度?