"CSS position 속성"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-==참고 자료== +==참고==))
 
(다른 사용자 한 명의 중간 판 6개는 보이지 않습니다)
3번째 줄: 3번째 줄:
;CSS position 속성
;CSS position 속성


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


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


==같이 보기==
==같이 보기==
*[[CSS position absolute, fixed 차이 상세]]
* [[CSS position absolute, fixed 차이 상세]]
*[[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]]

2017년 6월 27일 (화) 00:56 기준 최신판

1 개요[ | ]

CSS position Property
CSS position 속성
static (기본값) 위에서 아래로 순서대로 배치됨. top, left 지정 무시됨
relative 상대적인 위치
absolute 절대적인 위치(부모 기준)[1]. 스크롤시 그에 따라 움직임
fixed 절대적인 위치(화면 기준). 스크롤해도 화면 위치 그대로 고정됨

2 예시[ | ]

<style>
.container {
	margin: 5px;
	height: 100px;
	background: silver;
	font-size: 20px;
}
.box {
	width: 40px; height: 30px;
}
.box-static {
	position: static;
	left: 30px; top: 30px;
	background-color: red;
}
.box-relative {
	position: relative;
	left: 30px; top: 30px;
	background-color: orange;
}
.box-absolute {
	position: absolute;
	left: 200px; top: 30px;
	background-color: yellow;
}
.box-fixed {
	position: fixed;
	left: 300px; top: 30px;
	background-color: green;
}
</style>
 
<div class='container'>A
	<div class='box box-static'>static1</div>
	<div class='box box-static'>static2</div>
</div>
<div class='container'>B
	<div class='box box-relative'>relative1</div>
	<div class='box box-relative'>relative2</div>
</div>
<div class='container'>C
	<div class='box box-absolute'>absolute1</div>
	<div class='box box-absolute'>absolute2</div>
</div>
<div class='container'>D
	<div class='box box-fixed'>fixed1</div>
	<div class='box box-fixed'>fixed2</div>
</div>
<div class='container'>E</div>
<div class='container'>F</div>
<div class='container'>G</div>
→ static1, static2는 left, top이 무시되고 "가" 아래로 차례로 출력됨
→ relative1, relative2는 "나" 아래를 원점으로 하여 (40, 40) 위치부터 차례로 출력됨
→ absolute1, absolute2는 화면 기준으로 (100, 40) 위치에 겹쳐 출력됨
→ fixed1, fixed2는 화면 기준으로 (200, 40) 위치에 겹쳐 출력됨. ( 단, 스크롤해도 고정되어 있음 )

3 같이 보기[ | ]

4 주석[ | ]

  1. 단, 부모가 static(기본값)이면 화면의 (0, 0)이 기준이 됨

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}