cssFloat style property | styleFloat style property
cssFloat | ||||||
styleFloat |
Specifies or returns the horizontal alignment of the object.
With this property you can enable floating on the left or right side of an element.
If float is set, the display property is ignored and the element is shown as a block-level element.
Block element means that by default the entire line where the element appears is reserved.
With the styleFloat property you can specify which side of the element HTML content may appear on.
Syntax:
You can find the related objects in the Supported by objects section below.
cssFloat: | This property is read/write. |
styleFloat: | This property is read/write. |
CSS page for this property: float |
Possible values:
The type of this property is string.
One of the following values:
Takes the value of this property from the computed style of the parent element. | |||||||
Surrounding content flows to the right of the element. | |||||||
Default. The element is not floated. | |||||||
Surrounding content flows to the left of the element. |
Default: none.
Example HTML code 1:
This example illustrates the use of the float property:
|
||||
<head> <style> .floating { float: left; background: cyan; height: 30px; } .clear { clear: left; } </style> </head> <body> <i class="floating">Floating element</i> <div class="clear"> This sentence forbids floating elements on the left side. </div> <br /><br /> <i class="floating">Floating element</i> <div> This sentence does not forbid floating elements on the left side. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the styleFloat and cssFloat properties in JavaScript:
|
||||
<head> <style> .floating { float: left; background: cyan; height: 50px; } .clear { clear: left; } </style> <script type="text/javascript"> function ChangeFloating (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var selectState = selectTag.options[whichSelected].text; var floatTest = document.getElementById ("floatTest"); if ('cssFloat' in floatTest.style) { floatTest.style.cssFloat = selectState; } else { floatTest.style.styleFloat = selectState; } } function ChangeClear (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var selectState = selectTag.options[whichSelected].text; var clearTest = document.getElementById ("clearTest"); clearTest.style.clear = selectState; } </script> </head> <body> <i id="floatTest" class="floating">Floating element</i> <div id="clearTest" class="clear">Change the relation of this sentence and the floating element with the drop-down list.</div> <br /> <table cellpadding="5px"> <thead> <th>Floating style</th> <th>Clear type of the sentence</th> </thead> <tbody> <tr> <td align="center" valign="top"> <select onchange="ChangeFloating (this);" size="3"> <option />none <option selected="selected"/>left <option />right </select> </td> <td align="center" valign="top"> <select onchange="ChangeClear (this);" size="4"> <option />both <option selected="selected"/>left <option />right <option />none </select> </td> </tr> </tbody> </table> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, applet, b, bdo, big, blink, blockquote, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, object, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, textarea, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments