![009_포지션](https://inblog.ai/_next/image?url=https%3A%2F%2Finblog.ai%2Fapi%2Fog%3Ftitle%3D009_%25ED%258F%25AC%25EC%25A7%2580%25EC%2585%2598%26logoUrl%3Dhttps%253A%252F%252Finblog.ai%252Finblog_logo.png%26blogTitle%3Dchodong&w=1920&q=75)
Contents
포지션(position)
- position은 기본적인 속성은 static이다. → position: static; (기본 속성이라 생략 가능) → 일반적인 문서의 흐름에 따라 자연스럽게 흘러가는 속성이다.
- 출력 예시
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb1939378-3cd6-4f1f-9032-6c4df0711232%2F7c50e197-e53e-458c-8c82-ed0efaf0a526%2FUntitled.png?table=block&id=3954d3c7-220d-4dfd-9f7d-b2848ef32450&cache=v2)
출력 코드
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; } .box5 { width: 300px; height: 300px; background-color: bisque; display: inline-block; } </style> </head> <body> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"></div> <div class="box5"></div> </body> </html>
- relative → position: relative; → 내 앞에 있는 엘레멘트의 상대적 위치를 결정한다.
- 출력 예시
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb1939378-3cd6-4f1f-9032-6c4df0711232%2Ff2b4fecc-1202-4ed7-963f-3a416785bcb8%2FUntitled.png?table=block&id=1d87e24a-787a-4a5a-b2c1-63ae592717fd&cache=v2)
출력 코드
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; position: relative; top: 100px; left: 100px; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; } .box5 { width: 300px; height: 300px; background-color: bisque; display: inline-block; } </style> </head> <body> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"></div> <div class="box5"></div> </body> </html>
- absoulte → position: absoulte; → 도화지를 한 장 더 얹어서 그 위에 그림을 그리는 것 (Z 인덱스)
- 출력 예시
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb1939378-3cd6-4f1f-9032-6c4df0711232%2F2dcb06cd-6f7c-4d99-bef1-60d6af45aa1d%2FUntitled.png?table=block&id=6d86a46c-9436-4af0-86c3-41ec69bcc115&cache=v2)
출력 코드
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; position: absolute; top: 100px; left: 100px; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; } .box5 { width: 300px; height: 300px; background-color: bisque; display: inline-block; } </style> </head> <body> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"></div> <div class="box5"></div> </body> </html>
모든 그림을 그리는 시스템은 자식을 먼저 그리고 부모를 그린다.
그로인해 그림이 아래처럼 그려진다.
출력 2![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb1939378-3cd6-4f1f-9032-6c4df0711232%2F6f1f9f08-8a1f-4925-a6e2-ffad096f2937%2FUntitled.png?table=block&id=0e9e6034-33b3-41d2-8102-add45de5f247&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb1939378-3cd6-4f1f-9032-6c4df0711232%2Fed08fcad-7a01-411f-bd0f-db86ccfe9bd5%2FUntitled.png?table=block&id=cb2aed33-ebb0-4229-8ad6-dd508dd5c944&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb1939378-3cd6-4f1f-9032-6c4df0711232%2F6f1f9f08-8a1f-4925-a6e2-ffad096f2937%2FUntitled.png?table=block&id=0e9e6034-33b3-41d2-8102-add45de5f247&cache=v2)
출력 코드
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; } .box5 { width: 100px; height: 100px; background-color: bisque; display: inline-block; top: 50px; left: 50px; } </style> </head> <body> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"> <div class="box5"></div> </div> </body> </html>
출력 1
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb1939378-3cd6-4f1f-9032-6c4df0711232%2Fed08fcad-7a01-411f-bd0f-db86ccfe9bd5%2FUntitled.png?table=block&id=cb2aed33-ebb0-4229-8ad6-dd508dd5c944&cache=v2)
출력 코드
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; position: relative; } .box5 { width: 100px; height: 100px; background-color: bisque; display: inline-block; position: absolute; top: 50px; left: 50px; } </style> </head> <body> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"> <div class="box5"></div> </div> </body> </html>
→ 부모를 relative를 걸고 자식을 absolute를 걸면 부모 안에서 자식이 놀게 된다. (문법)
→ 자식 absolute는 부모 relative 안에서 논다.
- fixed → position: fixed; → 화면의 스크롤을 내려도 위치가 고정되게 하는 것 → 브라우저를 기준으로 위치를 고정
Share article