HTML DOM 스타일 objectPosition 속성은 HTML 문서의 자체 콘텐츠 상자에 이미지 또는 비디오 요소의 위치를 지정하는 방법을 반환하고 수정합니다.
구문
다음은 구문입니다 -
1. objectPosition 반환
object.objectPosition
2. objectPosition 수정
object.objectPosition = “value”
여기서 값은 -
일 수 있습니다.| 값 | 설명 |
|---|---|
| 초기 | 이 속성 값을 기본값으로 설정합니다. |
| 상속 | 상위 요소에서 이 속성 값을 상속합니다. |
| 위치 | 컨텐츠 상자 내부의 이미지 또는 비디오 요소의 위치를 나타냅니다. |
HTML DOM 스타일 objectPosition Property의 예를 살펴보겠습니다. -
예시
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #8BC6EC;
background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
text-align: center;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
.img-class {
width: 200px;
height: 250px;
object-fit: cover;
}
</style>
<body>
<h1 style="text-align:center">DOM Style objectPosition Property Demo</h1>
<img alt="Learn Java Swing" src="https://www.tutorialspoint.com/swing/images/swing-mini-logo.jpg" class="img-class" width='300' height='200'>
<button class="btn" onclick="set()">Set objectPosition</button>
<script>
function set() {
document.querySelector('.img-class').style.objectPosition = "100% 100%";
}
</script>
</body>
</html> 출력

"객체 위치 설정을 클릭합니다. ” 버튼을 사용하여 이미지 요소의 개체 위치 속성 설정 -
