HTML DOM Style overflow 屬性
定義和用法
overflow 屬性設置或返回如何處理呈現在元素框外面的內容。
語法
設置overflow 屬性:
Object.style.overflow="visible|hidden|scroll|auto|inherit"
返回overflow 屬性:
Object.style.overflow
值 | 描述 |
---|---|
visible | 默认。内容不会被修剪,会显示在元素框之外。 |
hidden | 内容会被修剪,元素框外面的内容不会被显示,浏览器不会显示滚动条。 |
scroll | 浏览器会显示滚动条,如果需要内容会被修剪。 |
auto | 内容会被修剪,如果需要则显示滚动条。 |
inherit | overflow 属性的值从父元素继承。 |
瀏覽器支持
所有主要瀏覽器都支持overflow 屬性。
注意: IE7及更早的版本不支持"inherit"值。IE8 只有規定了!DOCTYPE 才支持"inherit"。 IE9 支持"inherit"。
提示和註釋
提示:如果您想要隱藏整個文檔的滾動條,請在body或html元素上使用overflow屬性。
實例
實例
使用overflow 屬性來隱藏溢出的內容:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<style type="text/css">
div{
border:1px solid red;
width:100px;
height:100px;
}
</style>
<script>
function displayResult(){
document.getElementById("div1").style.overflow="hidden";
}
</script>
</head>
<body>
<div id="div1">
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
</div>
<br>
<input type="button" onclick="displayResult()" value="隐藏溢出">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<style type="text/css">
div{
border:1px solid red;
width:100px;
height:100px;
}
</style>
<script>
function displayResult(){
document.getElementById("div1").style.overflow="hidden";
}
</script>
</head>
<body>
<div id="div1">
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
这是一些文本。这是一些文本。
</div>
<br>
<input type="button" onclick="displayResult()" value="隐藏溢出">
</body>
</html>
嘗試一下»
Style對象