패딩 사용 요소의 패딩을 설정하려면 JavaScript의 속성을 사용하십시오. 다음 코드를 실행하여 JavaScript로 요소 패딩을 추가할 수 있습니다. −
예시
<!DOCTYPE html>
<html>
<head>
<style>
#box {
border: 2px solid #FF0000;
width: 150px;
height: 70px;
}
</style>
</head>
<body>
<div id = "box">This is demo text.</div>
<br><br>
<button type = "button" onclick = "display()">Add Padding</button>
<script>
function display() {
document.getElementById("box").style.padding = "20px 30px 10px 50px";
}
</script>
</body>
</html>