如何动态增加< div />基于内容? [英] How to dynamically increase the height of a <div /> based on the contents?

查看:125
本文介绍了如何动态增加< div />基于内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面上的div,我需要把内容放进去。有时内容是几行高,有时内容大于屏幕高度之间的不同大小。

I have a div on a page that I need to put content into. Sometimes the content is a few lines high, and sometimes the content is more than the screen height with varying sizes in between.

div下面有内容,所以我需要正确地压下内容,所以下面的内容总是在div下面。

There is content below the div so I need that content to be pushed down appropriately, so the content below is always right below the div.

基本上,它如下所示:

<div id="MainContentArea"><!-- my content --></div>

<div id="BottomContentArea"><!-- pre-existing content --></div>

我很容易为#MainContentArea指定一个高度,但我希望高度可以动态调整。有人可以告诉我怎么做吗?感谢。

It's easy for me to specify a height for the #MainContentArea but I want the height to be adjusted dynamically. Can somebody please show me how to do this? Thanks.

推荐答案

垂直调整以适合内容是预期的行为。如果您在css中的某处指定了浮动,您可能需要清除它们:

Resizing vertically to fit the content is the expected behavior. If you have specified floats somewhere in your css you may need to clear them:

<div style="clear:both;"></div>

这篇关于如何动态增加&lt; div /&gt;基于内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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