笑故挽风 2011-07-11 18:50 采纳率: 100%
浏览 749
已采纳

让主体的浏览器高度为100%

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.

转载于:https://stackoverflow.com/questions/6654958/make-body-have-100-of-the-browser-height

  • 写回答

21条回答 默认 最新

  • 妄徒之命 2011-07-11 18:53
    关注

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

    html, 
    body {
        height: 100%;
    }
    

    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.

    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%;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(20条)

报告相同问题?

悬赏问题

  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导