CSS Attributes Index Box Attributes
Sets or retrieves whether the object floats, causing text to flow around it.
CSS |
{ float: 'none' | 'left' | 'right' } |
Script |
object.style.styleFloat = sFloat ] |
none |
Object will be displayed where it appears in the text. |
left |
Text will flow to the right of the object. |
right |
Text will flow to the left of the object. |
The property is read/write with a default value of none; the CSS attribute has a default value of none and is not inherited.
With a value of left or right, the object is treated as block-level ( that is, the display property is ignored ). For example, floating paragraphs allow the paragraphs to appear side-by-side on a page.
Objects following a floating object flow in relation to the position of the floating object.
The floating object is moved left or right until it reaches the border, padding, or margin of another block-level object.
DIV and SPAN objects must have a width set for the float attribute to render.
The following example shows the float attribute affecting the flow of the text. The sphere image floats to the left of the text, and the cone floats to the right.
<img src="sample.jpg" style="float:left">
<img src="sample.jpg" style="float:right">
This feature requires Microsoft® Internet Explorer® 4.0 or later.
Show me
The following example demonstrates use of the styleFloat property. When the user mouses over the button, the images are swapped using inline scripting and the styleFloat property.
<img id=oSphere src="sphere.jpg" STYLE="float:left">
<img id=oCone src="cone.jpg" STYLE="float:right">
...
<button
onmouseover="oSphere.style.styleFloat='right';
oCone.style.styleFloat='left'"
onmouseout="oSphere.style.styleFloat='left';
oCone.style.styleFloat='right'">Flip-flop images.
</button>
This feature requires Microsoft® Internet Explorer® 4.0 or later.
Show me
clear