使身体具有浏览器高度的100% [英] Make body have 100% of the browser height

查看:92
本文介绍了使身体具有浏览器高度的100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让身体有100%的浏览器高度。我可以使用CSS吗?

I want to make body have 100% of the browser height. Can I do that using CSS?

我尝试设置 height:100%,但它不工作。

I tried setting height: 100%, but it doesn't work.

我想为页面设置一个背景颜色来填充整个浏览器窗口,但如果页面内容很少,底部会出现一个丑陋的白色条。 / p>

I want to set a background color for a page to fill the entire browser window, but if the page has little content I get a ugly white bar at the bottom.

推荐答案

尝试将html元素的高度设置为100%。

Try setting the height of the html element to 100% as well.

html, 
body {
    height: 100%;
}

正文寻找到其父级(HTML)如何缩放动态属性,因此HTML元素还需要设置其高度。

Body looks to its parent (HTML) for how to scale the dynamic property, so the HTML element needs to have it's height set as well.

但是body的内容可能需要动态更改。
将最小高度设置为100%将实现这一目标。

However the content of body will probably need to change dynamically. Setting min-height to 100% will accomplish this goal.

html {
  height: 100%;
}
body {
  min-height: 100%;
}

这篇关于使身体具有浏览器高度的100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆