I'm fairly new to CSS, so, this might look silly:
In CSS, i use the property to float:left
to position a content left to the neighbouring element, now, i have a container for all the elements that have the float property. how do i make the parenting element adjust it's height according to it's content?
the HTML:
<div id="page">
<div id="side">
<p>my sidebar</p>
</div>
<div id="content">
<p>my content</p>
<p>my content1</p>
<p>my content2</p>
<p>my content3</p>
</div>
the CSS
/* the "border:3px solid #000;" are used to make the div border visble*/
#page{
position:relative;
width:400px;
background-color: #F4F0EC;
border:3px solid #000;
}
#side{
border:3px solid #000;
float:left;
}
#content{
float:left;
border:3px solid #000;
}
with the above, the <div id="page">
look like it has a height of 0px.... how do i make it warp the content ??
since i'm new to CSS, please explain what am i doing wrong, thanks
Fiddle:http://jsfiddle.net/AuSmP/
The reason why the height or the containers is 0 is because you are floating all the content inside them and floated elements don't expand the height (or width) of their parents.
The float property still exists in CSS as it did when Internet Explorer was a young browser, and still works the same.
Absolutely positioned page elements will not affect the position of other elements and other elements will not affect them, whether they touch each other or not. There are four valid values for the float property. Left and Right float elements those directions respectively.
You can add overflow:hidden
for your div #page
which will allow it to resize to fit its contents.
See Working Demo.
Learn more about overflow property.
Alternatively you can also add <div class="clear"></div>
and then CSS
.clear{clear:both;}
to achieve the same.
See Demo.
Changing Position from relative to absolute can also help you out
Check this JSFiddle Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With