2012-02-07 77 views
0

我有一個關於css風格的問題,我想將max-height設置爲outer。當我只設置高度時,它工作正常,但是當我想將其設置爲最大高度時,內部的內容消失。將div風格設置爲最大高度

你可以在這裏的例子:http://sara.hil.ch/grega/example5.html

有什麼建議?

//outer div style 
div.dogodkiinhalt { 
     position: relative; 
     top: 0px; 
     left: 0px; 
     width: 400px; 
     padding-bottom: 0px; 
     background: blue; 
     border: none; 
     overflow: auto; 
     visibility: visible; 
     height: 200px; 

    } 
//inner div style 
    #inhaltbox { 
     position: absolute; 
     top: 0px; 
     overflow: hidden; 
     width: 400px; 
     height: 200px; 
     display: none; 
     display: block; 
    } 
+0

使用both:height和max-height。它工作正常 – Hadas 2012-02-07 15:25:31

+0

這是在發生什麼瀏覽器? – 2012-02-07 15:28:56

+0

在mac或win上的firefox上它是一樣的。 – greg 2012-02-07 17:45:06

回答

1

是的,如果你設置max-height - 什麼會最小高度呢?零!您也需要設置min-heightheight

此外,這裏還有一些問題。

div.dogodkiinhalt { 
     position: relative; 
     top: 0px; <-- not needed 
     left: 0px; <--- not needed 
     width: 400px; 
     padding-bottom: 0px; 
     background: blue; 
     border: none; 
     overflow: auto; 
     visibility: visible; <--- not needed 
     height: 200px; 

    } 
//inner div style 
    #inhaltbox { 
     position: absolute; 
     top: 0px; <--- left or right also needs to be declared 
     overflow: hidden; 
     width: 400px; 
     height: 200px; 
     display: none; <--- 
     display: block; <--- Choose one, not both 
    } 
+0

好的,但我怎樣才能設置適合文本的div容器的高度?你知道..如果我把文字少於containers,高度必須小一些。我該如何設置? – greg 2012-02-07 17:47:31

+0

@greg你有任何文字開頭嗎?這聽起來像是當你經歷了你的消失DIV時,你什麼也沒有。那是對的嗎? – Matthew 2012-02-07 22:12:26

+0

是的,其實我發現沒有什麼。但爲什麼? – greg 2012-02-08 14:49:26