自强学堂
自强学堂:学习、分享、让你更强!
JavaScript 参考手册HTMLCSSJAVASCRIPTJQUERYSQLPHPBOOTSTRAPANGULARXML
 

HTML DOM Style clear 属性

Style 对象参考手册 Style 对象

定义和用法

clear 属性设置或返回元素相对浮动对象的位置。

语法

设置 clear 属性:

Object.style.clear="none|left|right|both|inherit"

返回 clear 属性:

Object.style.clear

描述
none默认。允许浮动对象出现在元素两侧。
left不允许浮动对象出现在元素的左侧。
right不允许浮动对象出现在元素的右侧。
both不允许浮动对象出现在元素的左侧或右侧。
inheritclear 属性的值应该从父元素继承。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 clear 属性。

注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。


实例

实例

不允许浮动对象出现在文本的左侧:

<html>
<head>
<style type="text/css">
img
{
float:left;
}
</style>
<script>
function displayResult()
{
document.getElementById("p1").style.clear="left";
}
</script>
</head>
<body>

<img src="w3javascript.gif" width="100" height="132">

<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>

<input type="button" onclick="displayResult()" value="Clear left side of text">

</body>
</html>

尝试一下 »


Style 对象参考手册 Style 对象