CSS 高度不是 100%
我检查了很多与此类似的其他问题,但似乎没有解决方案。我有一个网站,有一个主体,然后是一个称为内容的内部 div。我已经尝试过:
body
{
height: 100%;
}
content
{
height: 100%;
}
并且
body
{
}
content
{
position: absolute;
top: 0px;
bottom: 0px;
}
这是大多数问题的答案。但由于某种原因,它对我们不起作用。当我们使用绝对定位进行强制时,它会拉伸到超过页面长度,并且当我们希望内容居中时也会将内容推向左侧(使用 margin-left: auto; margin-right:auto;)
有什么建议吗?
I have checked a lot of other questions similar to this, but it seems no solution works. I have a website that has a body, then an inner div called content. I have tried:
body
{
height: 100%;
}
content
{
height: 100%;
}
AND
body
{
}
content
{
position: absolute;
top: 0px;
bottom: 0px;
}
which were the answers to most of the questions. but for some reason it is not working for us. When we do the forcing with the absolute positioning, it stretches to more than the page length and also pushes our content to the left when we want it centered (using margin-left: auto; margin-right:auto;)
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了 body 和 div 之外,您还需要将 html 设置为 100% 高度,例如
You need to set html to 100% height in addition to body, and your div, e.g.
我的解决方案:
效果很好。属性
background: red;
用于测试。My solution:
Works fine. Attribute
background: red;
is for testing.