CSS 위치 속성
예시
<h2> 요소 위치 지정:
h2
{
position: absolute;
left: 100px;
top: 150px;
}
아래에서 더 많은 "직접 사용해 보기" 예를 살펴보세요.
정의 및 사용
속성 은 position
요소에 사용되는 위치 지정 방법의 유형(정적, 상대, 절대, 고정 또는 고정)을 지정합니다.
브라우저 지원
표의 숫자는 속성을 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.
Property | |||||
---|---|---|---|---|---|
position | 1.0 | 7.0 | 1.0 | 1.0 | 4.0 |
참고: 이 sticky
값은 Internet Explorer 또는 Edge 15 및 이전 버전에서 지원되지 않습니다.
CSS 구문
position: static|absolute|fixed|relative|sticky|initial|inherit;
속성 값
Value | Description | Play it |
---|---|---|
static | Default value. Elements render in order, as they appear in the document flow | |
absolute | The element is positioned relative to its first positioned (not static) ancestor element | |
fixed | The element is positioned relative to the browser window | |
relative | The element is positioned relative to its normal position, so "left:20px" adds 20 pixels to the element's LEFT position | |
sticky | The element is positioned based on the user's scroll position
A sticky element toggles between |
|
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
더 많은 예
예시
정상 위치를 기준으로 요소를 배치하는 방법:
h2.pos_left {
position: relative;
left: -20px;
}
h2.pos_right {
position: relative;
left: 20px;
}
예시
더 많은 포지셔닝:
#parent1 {
position: static;
border: 1px solid blue;
width: 300px;
height: 100px;
}
#child1 {
position:
absolute;
border: 1px solid red;
top: 70px;
right: 15px;
}
#parent2 {
position: relative;
border: 1px solid blue;
width: 300px;
height: 100px;
}
#child2 {
position: absolute;
border: 1px solid red;
top: 70px;
right: 15px;
}
관련 페이지
CSS 튜토리얼: CSS 포지셔닝
HTML DOM 참조: 위치 속성