CSS background-position 속성
예시
배경 이미지를 배치하는 방법:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
아래에서 더 많은 "직접 사용해 보기" 예를 살펴보세요.
정의 및 사용
background-position
속성은 배경 이미지의 시작 위치를 설정합니다 .
팁: 기본적으로 배경 이미지 는 요소의 왼쪽 상단 모서리에 배치되고 수직 및 수평으로 반복됩니다.
기본값: | 0% 0% |
---|---|
상속: | 아니요 |
애니메이션 가능: | 예. 애니메이션 가능 에 대해 읽기 |
버전: | CSS1 |
자바스크립트 구문: | 개체 .style.backgroundPosition="센터" |
브라우저 지원
표의 숫자는 속성을 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.
Property | |||||
---|---|---|---|---|---|
background-position | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
참고: IE8 및 이전 버전은 한 요소에 여러 배경 이미지를 지원하지 않습니다.
CSS 구문
background-position: value;
속성 값
Value | Description | Play it |
---|---|---|
left top left center left bottom right top right center right bottom center top center center center bottom |
If you only specify one keyword, the other value will be "center" | |
x% y% | The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. Default value is: 0% 0% | |
xpos ypos | The first value is the horizontal position and the second value is the vertical. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and positions | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
더 많은 예
예시
배경 이미지를 상단 중앙에 배치하는 방법:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center top;
}
예시
배경 이미지를 오른쪽 하단에 배치하는 방법:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: bottom right;
}
예시
백분율을 사용하여 배경 이미지를 배치하는 방법:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 50% 50%;
}
예시
픽셀을 사용하여 배경 이미지를 배치하는 방법:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 50px 150px;
}
예시
다른 배경 속성을 사용하여 "영웅" 이미지를 만듭니다.
.hero-image {
background-image: url("photographer.jpg"); /* The
image used */
background-color: #cccccc; /* Used if the image is
unavailable */
height: 500px; /* You must set a specified height */
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover; /* Resize the background image to cover the entire container */
}
관련 페이지
CSS 튜토리얼: CSS 배경
CSS 참조: background-image 속성
HTML DOM 참조: backgroundPosition 속성