0

I have an outer div

position: relative;
overflow: hidden;
min-heigth: 450px;

containing a div

position: absolute;
top: 10px;
right: 10px;

The inner div is bigger than the min-heigth of the outer div and I see that the outer div is not scaling to the content of the inner div. Capping off the bottom content of the inner div.

How can I define the outer (or inner) div to scale vertically to the content (of the inner div)

Thanks

2
  • 1
    Don't absolutely position the inner div. Could you make a jsFiddle test case of your HTML/CSS? Commented May 19, 2011 at 10:00
  • Possibly irrelevant to your question, but thought I'd mention that if this is a direct cut-n-paste from your CSS, then you have a typo: min-heigth: 450px; should be min-height: 450px;. That could cause other issues. If it's not a direct cut-n-paste then disregard :) Commented May 19, 2011 at 10:11

4 Answers 4

1

@trascher; It's possible but you have add extra markup because when you give a child div an absolute position then it's parent div is not consider it's height.

Check this http://jsfiddle.net/sandeep/6UksD/1/

CSS:

#outer
{
    position: relative;
    min-height: 450px;
    background:red;
    margin:10px 0 0 10px;
    width:200px;
    overflow: hidden;
}
#inner
{
    position:relative;
    background:black;
    height:600px;
    width:100px;
    margin:10px 0 0 10px;
    float:left;
}
#abinner
{
    position:absolute;
    background:yellow;
    height:100%;
    width:100%;
}

HTML:

<div id="outer">
    <div id="inner">
        <div id="abinner"></div>
    </div>

</div>
Sign up to request clarification or add additional context in comments.

Comments

0

First remove the min-heighton your outer div, and then instead of absolutely positioning the inner one, put a 10px padding on the outer one.

#outerDiv {
  position:relative;
  overflow:hidden;
  padding:10px;
}

#innerDiv {
  /*Stuff*/
}

Do provide us with an example though, it's hard to see the context...

Comments

0

Here's the stuff

<div id="outer">
    <div id="inner"></div>
</div>

#outer
{
    width:300px;
     height:auto;

}
#inner
{
    width:200px;
    height:300px;

}

I think this is thing you want:http://jsfiddle.net/anish/ZjQTt/

set inner content height according to your wish.the outer div expanded automatically.

Comments

0

Absolute positioning doesn't increase the height of it's parent element.

  1. You either set the height of the outer div manually
  2. You make the inner div to have margin top/left of 10px
  3. You increase the height of the outer div using javascript.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.