html - 如何在内容较少的情况下将网页右下角的 div 对齐?

标签 html css xhtml cross-browser

我这里有这个极其简单的初始页面:http://iph0wnz.com

中间是主图形,后面是我的“a”。右下角的标志。我希望该 Logo 与整个 页面 的右下角对齐,这意味着如果页面中有很多文本内容,它会出现(即它不会悬停在顶部),但如果内容较少(就像现在一样),则它应该与屏幕的最底部对齐,而不是紧跟在内容之后。

我将尝试给出一个我在 How to align content of a div to the bottom? 中看到的文本示例:

    -----------------------------
    | less content, no scroll   |
    |                           |
    |                           |
    |                           |
    |                        a. |
    ----------------------------- (screen height)

    -----------------------------
    | more content, yes scroll  |
    | the quick brown fox jump- |
    | ped over the lazy dog an- |
    | d she sells sea shells on |
    | the sea shore and some o- |
    | ther random text is put   | (screen height)
    | here so there is a scroll |
    | bar because the content   |
    | is too much for one scre- |
    | en to show. okay, I think |
    | that is enough.           |
    |                        a. |
    -----------------------------

除了上面链接的其他问题,我还查看了 How do I force a DIV block to extend to the bottom of a page even if it has no content?但这对我也不起作用。

我知道这非常简单,但我只是厌倦了尝试我能找到的所有黑客和技巧。

另外,当实际内容进入时,我想使用这种方法将 Logo 放在网站上 - 这将是一个博客。

注意:如果需要实现此效果,我不介意使用 JavaScript 和 jQuery。

最佳答案

试试这个解决方案:

* { margin: 0; }
html, body { height: 100%; }
/* the bottom margin is the negative value of the footer's height */
.wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -142px; }
/* .push must be the same height as .footer */
.footer, .push { height: 142px; }

找到 here

编辑:来不及记住如何去做或解释它,但如果您需要更多帮助,请在谷歌上搜索“sticky footer”

关于html - 如何在内容较少的情况下将网页右下角的 div 对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1118513/

相关文章:

javascript - 删除其中一个列表时如何使动画更流畅

javascript - 使用 AngularJS 为每个页面添加导航和页脚

css - 为什么在浏览器中打开网站时没有任何显示?

html - 浏览器将什么视为页面?

html - 悬停时突出显示 div 内的非矩形部分

php - 使用 PHP 单击提交按钮后无法将数据保存到数据库中

CSS如何同时使颜色:orange when a DOM has .红色和.黄色?

javascript - 如何使用 setTimeout Javascript 在 Canvas 上绘制后隐藏元素

jquery - 可选 - 选择后,元素会改变其外观

html - 如何从 HTML 中的 OpenType 字体调用 'Swash'/'Stylistic Set' 字符?