我可以使用溢出y中div的高度百分比:滚动吗?

时间:2012-07-16 08:27:47

标签: html css

我可以在div-overflow中使用高度百分比:滚动吗? 标记:

<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>

2 个答案:

答案 0 :(得分:0)

据我所知,你不能。

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

答案 1 :(得分:0)

不使用百分比,而是使用视频高度(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;