【问题标题】:set div style to max-height将 div 样式设置为最大高度
【发布时间】:2012-02-07 15:20:20
【问题描述】:

我有一个关于 css 样式的问题,我想将 max-height 设置为 external 。当我只设置高度时它工作正常,但是当我想将它设置为最大高度时,内部的内容消失了。

您可以在此处获取示例: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;
    }

【问题讨论】:

  • 同时使用:高度和最大高度。它工作正常
  • 这是在什么浏览器中发生的?
  • 在mac或win上的firefox上是一样的。

标签: javascript html css styles


【解决方案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
    }

【讨论】:

  • 好的,但是如何设置 div 容器的高度以适合文本?你知道.. 如果我输入的文本少于容器高度,则它的高度必须更小。我该如何设置?
  • @greg 你有什么要开始的文字吗?听起来当您体验消失的 DIV 时,您什么都没有。对吗?
  • 因为如果你只有max-height(而不是min-heightheight)那么你的DIV应该只和里面的内容一样高。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-26
  • 2014-09-17
  • 1970-01-01
相关资源
最近更新 更多