HTML DOM Style right 属性
htmldomweb developmentfront end technology更新于 2024/5/23 19:24:17
HTML DOM Style right 属性用于返回并修改 HTML 文档中已定位 HTML 元素的 right 位置。
语法
以下是语法 −
1. 返回 right
object.right
2. 修改 right
object.right = “value”
此处,value 可以为 −
| Sr.No | Value &解释 |
|---|---|
| 1 | initial 将此属性值设置为其默认值。 |
| 2 | inherit 从其父元素继承此属性值。 |
| 3 | percentage(%) 以父元素宽度的百分比定义值。 |
| 4 | length 它以长度单位定义右侧的值。 |
| 5 | auto 它允许浏览器设置右侧位置的值。 |
让我们看一个 HTML DOM Style right 属性的示例 −
示例
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem 0;
}
.square {
width: 100px;
height: 100px;
background: #db133a6b;
position: relative;
}
.show {
font-size: 1.2rem;
margin: 1rem 0;
}
</style>
<body>
<h1>DOM Style right Property Demo</h1>
<div class='square'></div>
<button onclick="set()" class="btn">Set right position</button>
<script>
function set() {
document.querySelector('.square').style.right = "-400px";
}
</script>
</body>
</html>
输出

点击“设置右侧位置”按钮设置粉色方块的右侧位置。

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

