Style cssFloatPropiedad
Objeto Style
Definición y uso
La propiedad cssFloat establece o devuelve la alineación horizontal de un elemento.
Sintaxis
Establecer la propiedad cssFloat:
Object.style.cssFloat="left|right|none|inherit"
Devolver la propiedad cssFloat:
Object.style.cssFloat
| Valor | Descripción |
|---|---|
| left | El objeto/elemento flota a la izquierda del elemento padre. |
| right | El objeto/elemento flota a la derecha del elemento padre. |
| none | Predeterminado. El objeto/elemento no flota. |
| inherit | El valor de la propiedad cssFloat se hereda del elemento padre. |
Compatibilidad del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales admiten la propiedad cssFloat.
Nota:IE7 y versiones anteriores no admiten el valor "inherit". IE8 solo admite "inherit" si se especifica !DOCTYPE. IE9 admite "inherit".
Consejos y notas
Nota:Si hay demasiado poco espacio en una línea para el elemento flotante, este saltará a la siguiente línea. Este proceso continuará hasta que haya una línea con suficiente espacio.
Ejemplo
Ejemplo
Haga clic en los dos botones para establecer que la imagen flote a la izquierda o a la derecha del texto:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.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.html" width="100" height="132">
<p>Este es un párrafo.</p>
<p>Este también es un párrafo.</p>
<input type="button" onclick="floatRight()" value="Flotar a la derecha">
<input type="button" onclick="floatLeft()" value="Flotar a la izquierda">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.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.html" width="100" height="132">
<p>Este es un párrafo.</p>
<p>Este también es un párrafo.</p>
<input type="button" onclick="floatRight()" value="Flotar a la derecha">
<input type="button" onclick="floatLeft()" value="Flotar a la izquierda">
</body>
</html>
Pruébalo »
Objeto Style Otras extensiones