Div box within div box

Hi

I have a div box within a div box.

<div id =“outerbox”>
<div id = “innerbox”>

</div>
</div>

How do I make the outer box relative to the innerbox? So when the inner box expands the outerbox will expand with it.

It does that by default. :slight_smile:

If that’s not happening for you, it probably means that your inner box has something like position:absolute applied to it. That’s generally a bad idea. Perhaps post some more details about what you need here.

If that’s not happening for you, it probably means that your inner box has something like position:absolute applied to it. That’s generally a bad idea. Perhaps post some more details about what you need here.

In addition to what ralph said check that you haven’t given the outer element explicit dimension OR that you aren’t floating the in inner box.

Hi.

I also want it to contain text without it going outside the box.

When I put text in and if its too long it leaves the box.

Hi. I actually am floating the inner box, because i want it aligned to the right.
what is my alternative?

Apply overflow: hidden to the container, and make sure not to put a fixed height on the container.

Since nobody is coming right out and saying it, can we see some REAL code for what you are trying to do – as in the HTML and the CSS – as in ALL of it?

Trying to diagnose from tiny snippets is like doing brain surgery via telegraph.

Though from what you’ve described so far, it sounds like you’re declaring heights and positioning you shouldn’t be in the first place. Seeing the actual page would help confirm that so we can actually tell you where you are going wrong.

Hi. I messed up my code so badly that due to ultimate frustration, i’ve decided to start again from scratch.

Ive created an image which should give you an idea of what I want to achieve. (ignore the colors)

I think we’ve already mentioned what you need to know. Do you understand what was said above?

Hi, sorry I missed your post.

You mentioned that I should not put a fixed height on the box.

What if I want it to be a certain height and then have it expand if the content expands?

Sorry stupid question. TOPIC SOLVED.

Thanks guys.

You could use min-height instead of height.