Please look at this example and explain to me why the green <div>
does not wrap itself around the orange <div>
.
<div id='green'> <div id="orange"></div> </div> #green{ border: 20px solid #3D3; } #orange{ width :100px; height: 100px; border: 10px solid orange; float: left; }
Use "overflow: hidden" to avoid floating elements from wrapping a container's text. Unfortunately, any content of the content 's text will wrap underneath it: ![
For width it's easy, simply remove the width: 100% rule. By default, the div will stretch to fit the parent container. Height is not quite so simple. You could do something like the equal height column trick.
Try adding float:left
and display:block
to the outer div
see updated example - http://jsfiddle.net/jordanlewis/gDtSZ/1/
Elements do not expand to contain floated children by default.
There are a number of workarounds, such as floating the parent, using a clearfix or adding overflow: hidden
to the parent.
Personally, I try and use the latter.
Here is your jsFiddle working.
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