Reputation: 15682
<html>
<body>
<div id="content1">
<div id="text1">This text floats left</div>
<div id="images1"><img src="img.jpg" /></div> <!--Floats right-->
</div>
<div id="content2">Text 2</div>
</body>
</html>
When I try to do this, and try to make a layout like a table with two rows with the text floating left and the image floating right in the top row, all that comes up is that the content2-div is squashed into the content1-div. How can I keep them separate?
Upvotes: 21
Views: 85253
Reputation: 28200
overflow:hidden
on your content1 div will make it expand to include all floated children. (Of course, this will hide non-floated overflowing content.)
Upvotes: 0
Reputation: 1559
You have not closed off <div id="images1">
. If this div is closed and the Content divs arenot float left then it should work.
Upvotes: 0
Reputation: 30002
Apply:
#images1{
float:right;
}
#content2{
clear:both;
}
and fix your html markup
<div id="images1"><img src="img.jpg" /> <!--Floats right-->
close the div:
<div id="images1"><img src="img.jpg" /> <!--Floats right--></div>
Upvotes: 2
Reputation: 28208
clear your floats. Here is an article describing whats going on: Clearing A Float Element
Upvotes: -1
Reputation: 2482
I hope you need to add another div before <div id="content2">Text 2</div>
which will be <div style="clear:both;"></div>
Upvotes: 0
Reputation: 10495
You need to use clear:both;
on your #content2 div
If you really wanna learn everything about floats, check out this amazing tutorial: http://css.maxdesign.com.au/floatutorial/
Upvotes: 24