2013-09-28 68 views
1

我想添加背景到div。如果内容高度很小,背景将被切割。如果我加分高,当窗口高度小,有apeears滚动..请帮助)使Div标签像身体标签

+2

http://stackoverflow.com/questions/1575141/make-div-100-height-of-browser-window OR http://jsfiddle.net/JamesD/hr8sL/ – Ashish

回答

2

雅各布没事,只是添加一个宽度属性也

div { 
    height:100%; 
    width:100%; 
    background:#f00; 
    color:#fff; 
    position: fixed; 
} 
1

不知道如果我理解你的问题,但试试这个:

div { 
    width: 100%; 
    height:100%; 
    background:#f00; 
    color:#fff; 
    position: fixed; 
} 
0

为此,你应该使用一些JavaScript。

function wh() 
{ 
var height = window.innerHeight; 
var width = window.innerWidth; 

document.getElementById('--your div ID--').style.height = height; 
document.getElementById('--your div ID--').style.width = width; 
} 

现在在body load上调用该函数wh()。即,

<body onload="wh()"></body>