stretch outer div to inner div

Problem

You have floating contents inside a parent div and the parent div does not stretch to encompass all the contents.

Example

Jsfiddle of the below code is here

I am in the inner div.
#css to the above code. #outer { border:1px solid red; } #inner { background-color:blue; float:left; }

This will render as

contents don't stretch

Solution

Set the overflow:auto for the outer div as follows.

#outer {
    overflow:auto;
}

Problem solved. Here is the jsfiddle of the solution.

Output after applying overflow property to outer div.
stretch div to fit contents

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

1 Response to stretch outer div to inner div

  1. Acaspita says:

    Added, but now I have a vertical scroll…, how do I solve that?..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s