I have a <div>
which needs to be auto adjusted according to the content in it. How can I do this? Right now my content is coming out of the <div>
The class I have used for the div is as follows
box-centerside {
background:url("../images/greybox-center-bg1.jpg") repeat-x scroll center top transparent;
float:left;
height:100px;
width:260px;
}
Don't set
height
. Usemin-height
andmax-height
instead.I just used
And it was worked for me properly. This div had some of float lefted divs.
I have made some reach to do auto adjust of height for my project and I think I found a solution
This can be attached to prime
div
(e.g. warpper, but not tobody
orhtml
cause the page will not scroll down) in your css file and inherited by other child classes and write into themoverflow: inherit;
attribute.Notice: Odd thing is that my netbeans 7.2.1 IDE highlight
overflow: inherit;
asUnexpected value token inherit
but all modern browser read this attribute fine.This solution work very well into
I do not test it on previous versions of those browsers. If someone will check it, it will be nice.
---- Use only this incase of elements where you cannot use overflow, like tooltip
Else you can use overflow property or min-height according to your need.
Just write:
then
div
will automatically take the height of the content.use
min-height
instead ofheight