HTML DOM Style overflowY 属性
htmlweb developmentfront end technology更新于 2025/6/9 2:20:17
DOM Style overflowY 属性返回并修改当元素框内的内容溢出 HTML 文档的顶部/底部时应采取的操作。
语法
以下是语法 −
返回 overflowY
object.style.overflowY
修改 overflowY
object.style.overflowY = “value”
值
此处值可以为 -
| 值 | 说明 |
|---|---|
| scroll | 该属性会剪切内容,并在必要时添加滚动条。 |
| inherit | 该属性会从其父元素继承此属性值。 |
| initial | 该属性会将此属性值设置为其默认值。 |
| auto | 该属性会剪切内容,并在必要时添加滚动条。 |
| hidden | 该属性会隐藏元素外部的内容流 |
| visible | 它不会剪切内容,内容将溢出元素框。 |
示例
让我们看一个 Style overflowX 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background-image: linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%);
height: 100vh;
}
p {
border: 2px solid #fff;
height: 100px;
width: 200px;
}
.btn {
background: coral;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin-top: 4rem;
}
</style>
</head>
<body>
<h1>DOM Style overflowY Property Example</h1>
<p>
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
</p>
<button onclick="add()" class="btn">Change overflow</button>
<script>
function add() {
document.querySelector('p').style.overflowY = "scroll";
}
</style>
</head>
<body>
Ouput
这将产生以下输出 −

点击"更改溢出"按钮,将 overflowY 属性应用于滚动值 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

