如何使用JavaScript设置元素的上边距?
使用JavaScript中的marginTop属性设置顶部边距。您可以尝试运行以下代码来使用JavaScript设置元素的顶部边距吗?
示例
<!DOCTYPE html>
<html>
<head>
<style>
#myID {
border: 2px solid #000000;
}
</style>
</head>
<body>
<div id="myID">This is demo text.</div><br>
<button type="button" onclick="display()">Add top margin</button>
<script>
function display() {
document.getElementById("myID").style.marginTop = "150px";
}
</script>
</body>
</html>热门推荐
10 微信立冬祝福语简短
11 新年祝福语简短又好听
12 伴娘祝福语长文案简短
13 姐妹订婚刺绣祝福语简短
14 9字祝福语简短创意
15 高考成绩高分祝福语简短
16 书法朋友祝福语简短精辟
17 给新生的简短祝福语
18 送教授贺卡祝福语简短