let's get IT with DAVINA ๐Ÿ’ป

Position ๋ณธ๋ฌธ

DEV_IN/CSS

Position

๋‹ค๋นˆ์น˜์ฝ”๋“œ๐Ÿ’Ž 2023. 2. 9. 04:57

Position

  • ๋ฌธ์„œ ์ƒ์— ์š”์†Œ๋ฅผ ๋ฐฐ์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•œ๋‹ค.
  • top, right, bottom, left ์†์„ฑ์„ ํ†ตํ•ด ์š”์†Œ์˜ ์ตœ์ข… ์œ„์น˜๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค.
  • ์‚ฌ์šฉ๋ฒ•
    • ๊ธฐ์ค€์„ ์žก๋Š”๋‹ค. (ex. position: relative;)
    • ์ด๋™์‹œํ‚จ๋‹ค. (ex. top: 50px;)

block : ํ•œ ์ค„ ๋ชจ๋‘ ์ฐจ์ง€ (๋Œ€ํ‘œ element - <div>, <p> )

inline : ์ฝ˜ํ…์ธ  ํฌ๊ธฐ ๋งŒํผ๋งŒ ์ฐจ์ง€ (๋Œ€ํ‘œ element - <span>)

๊ฐ’ ์˜๋ฏธ

static ๊ธฐ์ค€ ์—†์Œ (๋ฐฐ์น˜ ๋ถˆ๊ฐ€๋Šฅ / ๊ธฐ๋ณธ๊ฐ’)
relative ์š”์†Œ ์ž๊ธฐ ์ž์‹ ์„ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜
absolute ๋ถ€๋ชจ(์กฐ์ƒ) ์š”์†Œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜
fixed ๋ทฐํฌํŠธ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜
stickey ์Šคํฌ๋กค ์˜์—ญ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜

Relative

์š”์†Œ๋ฅผ ์ผ๋ฐ˜์ ์ธ ๋ฌธ์„œ ํ๋ฆ„์— ๋”ฐ๋ผ ๋ฐฐ์น˜ํ•œ๋‹ค.

์š”์†Œ ์ž๊ธฐ ์ž์‹ ์˜ ์›๋ž˜ ์œ„์น˜(static์ผ ๋•Œ์˜ ์œ„์น˜)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜ํ•œ๋‹ค.

  • ์›๋ž˜ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์œ„์ชฝ(top), ์•„๋ž˜์ชฝ(bottom), ์™ผ์ชฝ(left), ์˜ค๋ฅธ์ชฝ(right)์—์„œ ์–ผ๋งˆ๋งŒํผ ๋–จ์–ด์งˆ ์ง€ ๊ฒฐ์ •ํ•œ๋‹ค.
  • ์œ„์น˜๋ฅผ ์ด๋™ํ•˜๋ฉด์„œ ๋‹ค๋ฅธ ์š”์†Œ์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค.
  • ๋ฌธ์„œ ์ƒ ์›๋ž˜ ์œ„์น˜๊ฐ€ ๊ทธ๋Œ€๋กœ ์œ ์ง€๋œ๋‹ค.
div#a {
	background: #52D4FF;
	position: static;
}

div#b {
	background: #FF63EA;
	position: relative;
	top: 0px;
	left: 100px;
}

div#c {
	background: #C5FF63;
	position: relative;
	top: 0px;
	left: 200px;
}

Absolute

์š”์†Œ๋ฅผ ์ผ๋ฐ˜์ ์ธ ๋ฌธ์„œ ํ๋ฆ„์—์„œ ์ œ๊ฑฐํ•œ๋‹ค.

๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์œ„์น˜์— ์žˆ๋Š” ์กฐ์ƒ ์š”์†Œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜ํ•œ๋‹ค.

  • ์กฐ์ƒ ์š”์†Œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์œ„์ชฝ(top), ์•„๋ž˜์ชฝ(bottom), ์™ผ์ชฝ(left), ์˜ค๋ฅธ์ชฝ(right)์—์„œ ์–ผ๋งˆ๋งŒํผ ๋–จ์–ด์งˆ ์ง€ ๊ฒฐ์ •ํ•œ๋‹ค.
  • ์กฐ์ƒ ์ค‘ Position์„ ๊ฐ€์ง„ ์š”์†Œ๊ฐ€ ์—†๋‹ค๋ฉด ์ดˆ๊ธฐ ์ปจํ…Œ์ด๋‹ ๋ธ”๋ก(<body>์š”์†Œ)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์‚ผ๋Š”๋‹ค. (static์„ ์ œ์™ธํ•œ ๊ฐ’)
  • ๋ฌธ์„œ ์ƒ ์›๋ž˜ ์œ„์น˜๋ฅผ ์žƒ์–ด๋ฒ„๋ฆฐ๋‹ค. (์•„๋ž˜์— ์žˆ๋Š” div๊ฐ€ ํ•ด๋‹น ์ž๋ฆฌ๋ฅผ ์ฐจ์ง€ํ•œ๋‹ค)
div#a {
	background: #52D4FF;
	position: static;
}

div#b {
	background: #FF63EA;
	position: absolute;
	top: 0px;
	left: 100px;
}

div#c {
	background: #C5FF63;
	position: absolute;
	top: 0px;
	left: 200px;
}

๋ถ€๋ชจ relative & ์ž์‹ absolute

Parent์—๊ฒŒ Position ๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ?

  • Parent์˜ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์‚ผ๋Š”๋‹ค.

Grandparent์—๊ฒŒ Position ๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ?

  • ํ•œ ๋‹จ๊ณ„ ์˜ฌ๋ผ๊ฐ€์„œ GrandParent์˜ Postion๊ฐ’์„ ์ฐพ์•„์„œ ๊ธฐ์ค€์ ์œผ๋กœ ์‚ผ๋Š”๋‹ค.

๋ถ€๋ชจ, ์กฐ์ƒ ์ „๋ถ€ ๋’ค์ ธ๋ด๋„ Position ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ? (Parent, GrandParent, <body>ํƒœ๊ทธ, <html>ํƒœ๊ทธ๊นŒ์ง€ )

  • window ๊ฐ์ฒด์˜ viewport๋ฅผ ๊ธฐ์ค€์ ์œผ๋กœ์‚ผ๋Š”๋‹ค. (DOM : Document Object Model)

Fixed

๋ทฐํฌํŠธ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์‚ผ๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ?

absolute๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋˜‘๊ฐ™์ด ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, absolute๋Š” ์กฐ์ƒ ์š”์†Œ์˜ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์ ์œผ๋กœ ์‚ผ๋Š” ๊ฐœ๋…์ด๋ฏ€๋กœ, ๋ทฐํฌํŠธ๋ฅผ ๊ธฐ์ค€์œผ์ ์œผ๋กœ ์‚ผ์œผ๋ ค๋ฉด fixed๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

  • ์š”์†Œ๋ฅผ ์ผ๋ฐ˜์ ์ธ ๋ฌธ์„œ ํ๋ฆ„์—์„œ ์ œ๊ฑฐํ•œ๋‹ค. ํŽ˜์ด์ง€ ๋ ˆ์ด์•„์›ƒ์— ์–ด๋– ํ•œ ๊ณต๊ฐ„๋„ ๋ฐฐ์ •ํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • ๋ทฐํฌํŠธ๋ฅผ ๊ธฐ์ค€์ ์œผ๋กœ ๋ถ™์–ด์žˆ๋‹ค (== ํ™”๋ฉด์— ๋ถ™์–ด์žˆ๋‹ค.)

'DEV_IN > CSS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

div์— img ๋„ฃ๊ธฐ (props)  (0) 2023.02.09
๊ธ€์ž ์ˆ˜ ์ดˆ๊ณผ์‹œ?  (0) 2023.02.09
GMT/UTC time ํ˜•์‹ โ€œ2023-02-02โ€ format์œผ๋กœ change  (0) 2023.02.08
react-datepicker  (2) 2023.02.08
React-Styled Components  (0) 2023.02.08
Comments