CSS position 속성 편집하기

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
3번째 줄: 3번째 줄:
;CSS position 속성
;CSS position 속성


{| class='wikitable'
==값 목록==
| static || (기본값) 위에서 아래로 순서대로 배치됨. top, left 지정 무시됨
*static: 위에서 아래로 순서대로 배치됨(기본값).top, left 지정 무시됨
|-
*relative: 상대적인 위치
| relative || 상대적인 위치
*absolute: 절대적인 위치(부모 기준)<ref>단, 부모가 static(기본값)이면 화면의 (0, 0)이 기준이 됨</ref>
|-
*fixed: 절대적인 위치(화면 기준). 스크롤해도 화면 위치 그대로 고정됨.
| absolute || 절대적인 위치(부모 기준)<ref>단, 부모가 static(기본값)이면 화면의 (0, 0)이 기준이 됨</ref>. 스크롤시 그에 따라 움직임
|-
| fixed || 절대적인 위치(화면 기준). 스크롤해도 화면 위치 그대로 고정됨
|}


==예시==
==예시==
17번째 줄: 13번째 줄:
<style>
<style>
.container {
.container {
margin: 5px;
  margin: 20px;
height: 100px;
  height: 200px;
background: silver;
  background-color: silver;
font-size: 20px;
  font-size: 30px;
}
}
.box {
.box {
width: 40px; height: 30px;
  width: 40px;
  height: 40px;
  left: 40px;
  top: 40px;
}
}
.box-static {
.box-a {
position: static;
  position: static;
left: 30px; top: 30px;
  background-color: red;
background-color: red;
}
}
.box-relative {
.box-b {
position: relative;
  position: relative;
left: 30px; top: 30px;
  background-color: green;
background-color: orange;
}
}
.box-absolute {
.box-c {
position: absolute;
  left: 100px;
left: 200px; top: 30px;
  position: absolute;
background-color: yellow;
  background-color: blue;
}
}
.box-fixed {
.box-d {
position: fixed;
  left: 200px;
left: 300px; top: 30px;
  position: fixed;
background-color: green;
  background-color: yellow;
}
}
</style>
</style>
 
<div class='container'>A
<div class='container'>
<div class='box box-static'>static1</div>
  <div class='box box-a'>A1</div>
<div class='box box-static'>static2</div>
  <div class='box box-a'>A2</div>
</div>
</div>
<div class='container'>B
<div class='container'>
<div class='box box-relative'>relative1</div>
  <div class='box box-b'>B1</div>
<div class='box box-relative'>relative2</div>
  <div class='box box-b'>B2</div>
</div>
</div>
<div class='container'>C
<div class='container'>
<div class='box box-absolute'>absolute1</div>
  <div class='box box-c'>C1</div>
<div class='box box-absolute'>absolute2</div>
  <div class='box box-c'>C2</div>
</div>
</div>
<div class='container'>D
<div class='container'>
<div class='box box-fixed'>fixed1</div>
  <div class='box box-d'>D1</div>
<div class='box box-fixed'>fixed2</div>
  <div class='box box-d'>D2</div>
</div>
</div>
<div class='container'>E</div>
<div class='container'></div>
<div class='container'>F</div>
<div class='container'></div>
<div class='container'>G</div>
<div class='container'></div>
</source>
</source>
:→ static1, static2는 left, top이 무시되고 "가" 아래로 차례로 출력됨
:→ (static) A1, A2는 left, top이 무시되고 "가" 아래로 차례로 출력됨
:→ relative1, relative2는 "나" 아래를 원점으로 하여 (40, 40) 위치부터 차례로 출력됨
:→ (relative) B1, B2는 "나" 아래를 원점으로 하여 (40, 40) 위치부터 차례로 출력됨
:→ absolute1, absolute2는 화면 기준으로 (100, 40) 위치에 겹쳐 출력됨
:→ (absolute) C2는 화면 기준으로 (100, 40) 위치에 출력됨<ref>C1은 C2 아래에 겹쳐 있어서 보이지 않음</ref>
:→ fixed1, fixed2는 화면 기준으로 (200, 40) 위치에 겹쳐 출력됨. ( 단, 스크롤해도 고정되어 있음 )
:→ (fixed) D2는 화면 기준으로 (200, 40) 위치에 출력됨. 단, 스크롤해도 고정되어 있음<ref>D1은 D2 아래에 겹쳐 있어서 보이지 않음</ref>
<jsfiddle height='300'>uj0msucv</jsfiddle>
:→ 예제: http://jmnote.com/css/position.php


==같이 보기==
==같이 보기==
* [[CSS position absolute, fixed 차이 상세]]
*[[CSS position absolute 상세]]
* [[CSS left, top 속성]]
*[[CSS left, top 속성]]
* [[CSS float 속성]]
*[[CSS float 속성]]
* [[jQuery .position()]]
* [[CSS 내비게이션바 상단 고정]]


==주석==
==주석==
<references/>
<references/>


==참고==
==참고 자료==
*http://www.w3schools.com/cssref/pr_class_position.asp
*http://www.w3schools.com/cssref/pr_class_position.asp


[[분류: CSS]]
[[분류: CSS]]

제타위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 제타위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)