【问题标题】:How can I make a div that spans the entire height of the document, even when it contains no content?如何制作一个跨越文档整个高度的 div,即使它不包含任何内容?
【发布时间】:2019-09-30 17:28:48
【问题描述】:

我想要一个名为“内容”的 div,它从页面顶部开始向下延伸到底部,即使没有其他内容。我试图弄清楚如何使用非常简单的 CSS 来做到这一点,这样我就可以在我现有的网站上实现它。这是我一直在玩的代码:

html {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}
body {
    position: absolute;
    top:0;
    bottom: 0;
    left: 0;
    right: 0;

}
#content
{
    position: relative;
    top: 0;
    margin: 0 auto;
    border: 1px solid red;
    width: 70%
}

这将创建一个 div,但它最终只是屏幕顶部的一条红线。如果我添加height: 900px;,那么它会起作用,但我会尽量不使用特定的测量值。

【问题讨论】:

    标签: html css height css-position


    【解决方案1】:

    使用min-height:100% 使其在必要时可以增长,并删除所有其他规则(它们没有做任何事情)。

    【讨论】:

      【解决方案2】:

      #content { height: 100%; ... }怎么样?

      【讨论】:

        猜你喜欢
        • 2023-03-24
        • 1970-01-01
        • 2019-10-10
        • 2014-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-07
        • 1970-01-01
        相关资源
        最近更新 更多