javascript - 将 div 样式设置为最大高度

标签 javascript html css styles

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

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

最佳答案

是的,如果您设置 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
    }

关于javascript - 将 div 样式设置为最大高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9178808/

相关文章:

javascript - HTML5视频时长

javascript - Vuejs 无法使用 CDN

html - 平滑旋转过渡 CSS3?

jquery - runat ="server"破坏了我的 jquery/css 功能

javascript - 如何在我的 html 循环中制作带有彩虹颜色的按钮?

javascript - 同位素布局问题

javascript - 如何根据媒体查询调用js文件

javascript - jQuery location.reload 在 ajax 成功后发生

javascript - 如何在 &lt;script&gt; 标签内的表单中添加更多输入

javascript - 排除 Javascript/DOM 中的元素