如何使用JavaScript设置用于元素的定位方法的类型?
要设置位置,请使用JavaScript中的 position 属性。您可以尝试运行以下代码来设置用于JavaScript元素的定位方法的类型-
示例
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 350px;
height: 200px;
background-color: orange;
border: 3px solid red;
position: relative;
top: 20px;
}
</style>
</head>
<body>
<p>Click to set the type of positioning method using position property.</p>
<button type = "button" onclick = "display()">Set Position</button>
<div id = "box">
<p>This is a div. This is a div. This is a div. This is a div. This is a div.<p>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.<p>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.<p>
</div>
<br>
<br>
<script>
function display() {
document.getElementById("box").style.position = "absolute";
}
</script>
</body>
</html>热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短