CSS:如何获取固定高度的div内容器的滚动条 [英] CSS: how to get scrollbars for div inside container of fixed height

查看:679
本文介绍了CSS:如何获取固定高度的div内容器的滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下标记:

<div class="FixedHeightContainer">
  <h2>Title</h2>
  <div class="Content">
    ..blah blah blah...
  </div>
</div>

CSS看起来像这样:

The CSS looks like this:

.FixedHeightContainer
{
  float:right;
  height: 250px;
  width:250px;  
}
.Content
{
  ???
}

由于其内容, div的高度。内容通常大于由 div.FixedHeightContainer 提供的空间。目前, div.Content merrily扩展到底部div.FixedHeightContainer - 根本不需要。

Due to its content, the height of div.Content is typically greater than the space provided by div.FixedHeightContainer. At the moment, div.Content merrily extends out of the bottom of div.FixedHeightContainer - not at all what I want.

如何指定 div.Content 获取滚动条(最好是垂直的, )当它的高度太大而不适合?

How do I specify that div.Content gets scrollbars (preferably vertical only, but I'm not fussy) when its height is too great to fit?

overflow:auto c>

推荐答案

overflow 应该照顾它,但你需要设置 Content 的高度。如果没有设置height属性,div将会垂直增长到需要的高度,并且不需要滚动条。

setting the overflow should take care of it, but you need to set the height of Content also. If the height attribute is not set, the div will grow vertically as tall as it needs to, and scrollbars wont be needed.

请参阅示例:
http://jsfiddle.net/ftkbL/1/

这篇关于CSS:如何获取固定高度的div内容器的滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆