HTML DOM Style clear 屬性

2018-08-04 20:41 更新

Style clear 屬性

Style 對象參考手冊 Style 對象

定義和用法

clear 屬性設(shè)置或返回元素相對浮動對象的位置。

語法

設(shè)置 clear 屬性:

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

返回 clear 屬性:

Object.style.clear

描述
none 默認。允許浮動對象出現(xiàn)在元素兩側(cè)。
left 不允許浮動對象出現(xiàn)在元素的左側(cè)。
right 不允許浮動對象出現(xiàn)在元素的右側(cè)。
both 不允許浮動對象出現(xiàn)在元素的左側(cè)或右側(cè)。
inherit clear 屬性的值應(yīng)該從父元素繼承。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持 clear 屬性。

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


實例

實例

不允許浮動對象出現(xiàn)在文本的左側(cè):

<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 對象
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號