Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make outer div fit child divs?

There is two piecharts in fiddle. Why the content isn't fit with things that inside of it? What is the reason of overflowing charts out of the content? I want put these charts in to yellow content area. Being a css newbie i don't know that how i can fix it.

#content {
    width:80%;
    height:auto;
    margin-left:auto;
    margin-right:auto;
    padding: 10px 20px 30px 20px;
    background-color:yellow;
    color: #333333;
    font-family: Helvetica, Arial, sans-serif;
}

<div id="content"> 
    This is the content area
    <div id="piechart1" style="position:relative;top:20px;float:left;"></div>
    <div id="piechart2" style="position:relative;float:left;"></div>
</div>
like image 472
mcan Avatar asked Oct 15 '25 00:10

mcan


2 Answers

It's actually a very simple fix - just make the #content div overflow:auto . By default it won't expand to cover the child divs because they are both floated left, which effectively collapses them. Making the parent overflow:auto forces to expand to cover the width and height of the floated divs too.

http://jsfiddle.net/wuKFJ/5/

like image 125
Michael Low Avatar answered Oct 17 '25 15:10

Michael Low


#content {
    width:80%;
    height:auto;
    margin-left:auto;
    margin-right:auto;
    padding: 10px 20px 30px 20px;
    background-color:yellow;
    color: #333333;
    font-family: Helvetica, Arial, sans-serif;
    overflow: auto.
}
like image 25
AdityaSaxena Avatar answered Oct 17 '25 14:10

AdityaSaxena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!