Latest web development tutorials

HTML DOM Style cssFloat property

Style Object Reference Style Objects

Definition and Usage

cssFloat property sets or returns the horizontal alignment of elements.

grammar

Setting cssFloat properties:

Object.style.cssFloat="left|right|none|inherit"

Back cssFloat properties:

Object.style.cssFloat

描述
left 对象/元素浮到父元素的左边
right 对象/元素浮到父元素的右边
none 默认。对象/元素不浮动。
inherit cssFloat 属性的值从父元素继承。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support cssFloat property.

Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".


Tips and Notes

Note: If thespace is too small for the purposes of the floating element, then this element will jump to the next line in a row, this process will continue until there is a line up enough space.


Examples

Examples

Click on the buttons to set the image floats to the left and right edges of the text:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function floatRight () {
. Document.getElementById ( "img1") style.cssFloat = "right";
}
function floatLeft () {
. Document.getElementById ( "img1") style.cssFloat = "left";
}
</ Script>
</ Head>
<Body>

<Img id = "img1" src = "w3javascript.gif" width = "100" height = "132">
<P> This is a paragraph. </ P>
<P> This is a paragraph. </ P>
<Input type = "button" onclick = "floatRight ()" value = "floating right">
<Input type = "button" onclick = "floatLeft ()" value = "left floating">

</ Body>
</ Html>

try it"


Style Object Reference Style Objects