2013-08-20 78 views
1

我想有一個div默認高度爲height: 100%;,但如果div的內容不合適,我希望div動態擴展。默認div的高度

+0

你試過Welcome.what? – allen213

+0

雖然100%?有一個固定高度的父元素嗎? –

回答

7

min-height屬性可能會是你正在尋找:

分配

min-height: 100%; 

看到https://developer.mozilla.org/en-US/docs/Web/CSS/min-height

div將使它有其paremt元素的高度的100% 。 所以要確保周圍的元素(至少<html> & <body>)有100%的自己:

html, body{ 
    height: 100%; 
} 
0

您還可以設置高度

height:auto;  /* for IE as it does not support min-height */ 
min-height:100%;