Say I have something like the following code, where I want to display some text between two images that I am floating left and right.
Add this line to your CSS properties:
overflow: hidden
In CSS, floated elements do not add height to a parent by default.
The solution is simply to set overflow: hidden
.
<div style="border: 2px solid black; overflow: hidden;"
<img src="testImage1.png" alt="Test Image 1" style="float:right;" />
<img src="testImage2.png" alt="Test Image 2" style="float:left;" />
<p>Test Text</p>
</div>
fiddle: http://jsfiddle.net/JNets/
Adding an overflow
in this case with a value of hidden
or auto
remedies the issue.
Check the fiddle below:
http://jsfiddle.net/XMrwR/
Clearing floats the overflow way
http://www.quirksmode.org/blog/archives/2005/03/clearing_floats.html