如何让div采用屏幕的高度? [英] How can I make a div adopt the height of the screen?
本文介绍了如何让div采用屏幕的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用
height:100%
但是这使得div只和它的内容一样高 - 它只包含一个单词的文本。
如何强制div使用屏幕高度?
解决方案
您需要正文
和 html
元素才能拥有 100%
height。
尝试以下CSS:
html,body {
margin:0;
padding:0;
height:100%;
}
YourDivSelector {
height:100%;
}
边距和填充必须设置为0以防止在Firefox中自动滚动。 / p>
I tried using
height: 100%
but this makes the div only as high as its contents - it just contains a single word of text.
How can I force the div to use the screen height instead?
解决方案
You need the body
and html
elements to have 100%
height as well.
Try the following CSS:
html, body {
margin: 0;
padding: 0;
height: 100%;
}
YourDivSelector {
height: 100%;
}
The margin and padding must be set to 0 to prevent autoscroll in Firefox.
这篇关于如何让div采用屏幕的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文