Div高度100%,并展开以适合内容 [英] Div height 100% and expands to fit content

查看:175
本文介绍了Div高度100%,并展开以适合内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个div元素,其高度设置为100%。主体的高度也设置为100%。内部div有一个背景,所有这一切都不同于身体背景。这是为了使div的高度100%的浏览器屏幕高度,但问题是我有内部的div,垂直扩展超出浏览器的屏幕高度。当我向下滚动时,div在你不得不开始滚动页面的那一点结束,但是内容溢出。

I have a div element on my page with its height set to 100%. The height of the body is also set to 100%. The inner div has a background and all that and is different from the body background. This works for making the div height 100% of the browser screen height, but the problem is I have content inside that div that extends vertically beyond the browser screen height. When I scroll down, the div ends at the point at which you had to begin scrolling the page, but the content overflows beyond that. How do I make the div always go all the way to the bottom to fit the inner content?

这里是我的CSS的简化:

Here's a simplification of my CSS:

body {
    height:100%;
    background:red;
}

#some_div {
    height:100%;
    background:black;
}

一旦我滚动页面,黑色结束,内容流向红色背景。它似乎无关紧要是否将位置设置为相对或绝对的#some_div,问题发生任何一种方式。 #some_div中的内容大部分是绝对定位的,它是从数据库动态生成的,因此其高度无法预先知道。

Once I scroll the page, the blackness ends and the content flows onto the red background. It doesn't seem to matter whether I set the positon to relative or absolute on the #some_div, the problem occurs either way. The content inside the #some_div is mostly absolutely positioned, and it is dynamically generated from a database so its height can't be known in advance.

编辑:这里是问题的屏幕截图:

Here is a screenshot of the problem:

推荐答案

这里是你应该在CSS样式,在主DIV上做的

Here is what you should do in the CSS style, on the main DIV

display:block;
overflow:auto;

不要触摸高度

这篇关于Div高度100%,并展开以适合内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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