[英]How can I assign a height to an element, such that the height is equal to the height of the screen?
[英]How do I make an element's height equal to the height of the screen?
我嘗試了height: auto;
但這不起作用。 有任何想法嗎?
html, body { height: 100%; }
#container { height: 100%; background: red; width: 200px; }
這是您要做什么? 請提供一些代碼。
您有幾種選擇。 你可以做:
.element{
position:absolute;
top:0px;
right:0px;
left:0px;
bottom:0px;
}
這樣,它將從第一個父元素的每一側開始都是0px,且位置不是靜態的。 如果它是頁面上的第一個元素,它將填充整個文檔正文。
看到這里發生了什么: http : //jsfiddle.net/4QH8H/embedded/result/
http://jsfiddle.net/4QH8H/light/
您也可以這樣做:
.element{
height:100%;
width:100%;
}
盡管這些屬性只能使它和父元素一樣高和寬,並且有時正文僅會包裹內容而不填充頁面,因此您必須執行以下操作:
html, body{
height:100%;
width:100%;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.