2012-02-07 75 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