【问题标题】:Can i use percentage in height in div with overflow-y: scroll in it?我可以在带有溢出-y的div中使用高度百分比:滚动吗?
【发布时间】:2012-07-15 01:56:31
【问题描述】:

我可以在 div 中使用具有溢出-y 的高度百分比:滚动吗? 标记:

<div id="container">
<div class="messages_container">
<ol class="messages">
<li>sample message here</li>
<li>sample message here</li>
<li>sample message here</li>
</ol>
</div>
<div class="reply">
<form>
<fieldset>
<textarea cols="60" rows="1" name="message"></textarea>
<input type="checkbox" checked="checked">
<input type="submit" value="Submit"/>
</fieldset>
</form>
</div>

【问题讨论】:

    标签: html css


    【解决方案1】:

    据我所知,你不能。

    尝试用 JS 来做,应该比用 CSS 更容易。

    【讨论】:

      【解决方案2】:

      不使用百分比,而是使用视口高度 (vh),这在 stackoverflow thread 中进行了解释,我还做了一个 jsfiddle 自己查看

      所以而不是:

      display: block;
      width: 100%    
      height: 50%;
      overflow: hidden;
      overflow-y: auto;
      

      用途:

      display: block;
      width: 100vh;    
      height: 50vh;
      overflow: hidden;
      overflow-y: auto; 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-08
        • 2013-10-07
        • 2015-07-20
        • 2012-05-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多