CSS / Reference / background-position
개요
background-position은 배경 이미지의 위치를 정하는 속성입니다.
- 기본값 : 0% 0%
- 상속 : No
- 애니메이션 : Yes
- 버전 : CSS Level 1
문법
background-position: x-position y-position | initial | inherit
- x-position y-position : 가로 위치와 세로 위치를 정합니다.
- initial : 기본값으로 설정합니다.
- inherit : 부모 요소의 속성값을 상속받습니다.
위치 값으로 사용할 수 있는 것은 다음과 같습니다.
- 가로 위치 값 : left, center, right, 백분율, 길이
- 세로 위치 값 : top, center, bottom, 백분율, 길이
예제
- 왼쪽에서 10%, 위쪽에서 100px 위치에 배경 이미지를 배치합니다.
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>CSS</title>
<style>
div {
width: 100%;
height: 600px;
border: 1px solid #bcbcbc;
}
.a {
background-image: url( "images/bg-gray-400x300.png" );
background-repeat: no-repeat;
background-position: 10% 100px;
}
</style>
</head>
<body>
<div class="a">
</div>
</body>
</html>

- 배경 이미지를 가운데 배치합니다.
background-position: center center;










