Hi all,
I've been playing around with CSS floats, trying to understand how they work and I've come across a situation that doesnt make sense.
From my understanding, any non-float elements should flow right past. In the code below, #float1 is displayed on line 1 and #float2, #float3 are on the next.
After adding #txt I should expect it to be displayed next to #float1 but it's displayed on line 2. If #txt's width is not specified then it's displayed on line 1. This doesnt make sense, because line 1 has enough free space to fit #txt. Am I missing something??
Thanks
I've been playing around with CSS floats, trying to understand how they work and I've come across a situation that doesnt make sense.
From my understanding, any non-float elements should flow right past. In the code below, #float1 is displayed on line 1 and #float2, #float3 are on the next.
After adding #txt I should expect it to be displayed next to #float1 but it's displayed on line 2. If #txt's width is not specified then it's displayed on line 1. This doesnt make sense, because line 1 has enough free space to fit #txt. Am I missing something??
Thanks
Code:
<html> <head> <style type="text/css"> </style> </head> <body> <div style="width: 600px"> <div id="float1" style="float: left; width: 250px; background-color: red;position: relative">a</div> <div id="float2" style="float: right; width: 400px; background-color: red;position: relative">a</div> <div id="float3" style="float: right; width: 120px; background-color: red;position: relative">a</div> <div style="width: 100px" ID="txt">ass dasd asdsadas dsasadsd sa ds</div> </div> </body> </html>
Comment