【发布时间】:2014-09-19 21:51:58
【问题描述】:
我有一个预设“宽度”和“高度”的“div”。我需要根据内容更改该“div”的高度。我正在寻找一些 JavaScript,但找不到适合我的。
这是我的简单示例,需要改进http://jsfiddle.net/dmitry313/1zr6Lhwa/
HTML
<div id="content">
<h2>Text</h2>
<p>Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example </p>
</div>
CSS
h2 {
font:18px/30px Arial;
}
#content {
width:200px;
height:100px;
border:1px solid #000;
background: yellow;
}
编辑:最初预设的“宽度”和“高度”很重要,不能更改
【问题讨论】:
-
你为什么不用
height: auto;? -
您设置的最小预期尺寸是多少?还是 div 应该变成 0 高度和宽度?
-
@Alex 最初预设的“宽度”和“高度”很重要,不能更改
标签: javascript jquery html css ajax