Make body have 100% of the browser height

2018-12-31 04:53发布

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

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

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 css height
21条回答
若你有天会懂
2楼-- · 2018-12-31 05:42

If you don't want the work of editing your own CSS file and define the height rules by yourself, the most typical CSS frameworks also solve this issue with the body element filling the entirety of the page, among other issues, at ease with multiple sizes of viewports.

For example, Tacit CSS framework solves this issue out of the box, where you don't need to define any CSS rules and classes and you just include the CSS file in your HTML.

查看更多
梦寄多情
3楼-- · 2018-12-31 05:42

Try

<html style="width:100%; height:100%; margin: 0; padding: 0;">
<body style="overflow:hidden; width:100%; height:100%; margin:0; padding:0;">
查看更多
无与为乐者.
4楼-- · 2018-12-31 05:43
html, body
{
  height: 100%;
  margin: 0;
  padding: 0;
}
查看更多
登录 后发表回答