如何使用JavaScript设置元素的最高位置?
要设置最高位置,请使用JavaScript中的top 属性。您可以尝试运行以下代码以使用JavaScript设置div的顶部位置-
示例
<!DOCTYPE html>
<html>
<head>
<style>
#myID {
position: absolute;
}
</style>
</head>
<body>
<button onclick="display()">Set Top Position</button>
<div id = "myID">
This is demo text! This is demo text!
</div>
<script>
function display() {
document.getElementById("myID").style.top = "100px";
}
</script>
</body>
</html>热门推荐
10 新年祝福语长篇文案简短
11 新年祝福语简短给孩子
12 女神节祝福语漂亮简短
13 舅妈生日红包祝福语简短
14 喜事敬酒祝福语简短精辟
15 奶奶八十寿辰祝福语简短
16 形容新年的祝福语简短
17 上嫂子生日祝福语简短
18 想念老公生日祝福语简短