Issue
I have a "div" with preset "width" and "height". I need to change the height of that "div" based on content. I was looking for some JavaScript but couldn't find appropriate for me.
Here is my simple example, which needs an improvement 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;
}
EDIT: Initially preset "width" and "height" are important and can't be changed
Solution
Use min-height instead of height so that the <div> expands accordingly.
h2 {
font:18px/30px Arial;
}
#content {
width:200px;
min-height:100px;
border:1px solid #000;
background: yellow;
}
<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>
Answered By - T J
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.