JavaScript에서 배경 이미지의 크기를 설정하려면 backgroundSize를 사용하세요. 재산. 배경의 이미지 크기를 설정할 수 있습니다.
예시
다음 코드를 실행하여 배경 이미지의 크기를 설정하는 방법을 배울 수 있습니다.
<!DOCTYPE html>
<html>
<head>
<style>
#box {
border: 2px dashed blue;
width: 600px;
height: 400px;
background: url('https://www.tutorialspoint.com/videotutorials/images/coding_ground_home.jpg') no-repeat;
}
</style>
</head>
<body>
<button onclick="display()">Set size of background image</button>
<div id="box">
</div>
<script>
function display() {
document.getElementById("box").style.backgroundSize = "150px 200px";
}
</script>
</body>
</html>