简体   繁体   English

div /身高100%的固溶体

[英]Solid solution for div/body height 100%

I think we need to find a solid solution for this problem - on the internet, there does not seem to be one. 我认为我们需要为这个问题找到一个可靠的解决方案 - 在互联网上,似乎没有一个。

The DIV will always stay the height of its content - and not more. DIV将始终保持其内容的高度 - 而不是更多。

The structure is like this: 结构是这样的:

<html>
    <head>
        <title>myPage</title>
    </head>
    <body>
        <div id='container'>
            Some Content...
        </div>
    </body>
</html>

CSS usually looks like this: CSS通常看起来像这样:

body {
    height: 100%;
}
div#container {
    height: 100%;
    width: 100%;
}

There are already tricks with setting margin or/and padding on body or/and div, but nothing seems to work really fine. 已经设置了在body或/和div上设置margin或/和padding的技巧,但似乎没有什么工作真的很好。

Is there a one and only solution for this problem? 这个问题是否有唯一的解决方案?

html, body, div#container{
   min-height: 100%;
   height: 100%;
}

May be this will help? 可能这会有所帮助吗?

Try this: 试试这个:

html, body { height: 100%; margin: 0; padding:0; }
#container { height: auto; min-height:100%; background:#ccc; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM