Search

μœ„μΉ˜ 속성

μœ„μΉ˜ 속성

μœ„μΉ˜ μ„€μ • κΈ°μ€€κ³Ό 크기λ₯Ό μ§€μ •ν•˜λŠ” 속성
β€’
μœ„μΉ˜ 속성 μ’…λ₯˜
β€’
μœ„μΉ˜ μ„€μ • κΈ°μ€€
β—¦
static
β—¦
relative
β—¦
absolute
β—¦
fixed
β—¦
sticky
β€’
κΈ°λ³Έ μ˜ˆμ‹œ μ½”λ“œ
β€’
μœ„μΉ˜ 속성 ν™œμš©

μœ„μΉ˜ 속성 μ’…λ₯˜

속성
μ„€λͺ…
κΈ°λ³Έ μ˜ˆμ‹œ μ½”λ“œ
position
μš”μ†Œμ˜ μœ„μΉ˜ 지정 방식 μ„€μ •
position: relative;
top
μš”μ†Œμ˜ 상단 μœ„μΉ˜ μ„€μ •
top: 20px;
right
μš”μ†Œμ˜ 우츑 μœ„μΉ˜ μ„€μ •
right: 20px;
bottom
μš”μ†Œμ˜ ν•˜λ‹¨ μœ„μΉ˜ μ„€μ •
bottom: 20px;
left
μš”μ†Œμ˜ 쒌츑 μœ„μΉ˜ μ„€μ •
left: 20px;
z-index
μš”μ†Œμ˜ μŒ“μž„ μˆœμ„œ μ„€μ •
z-index: 10;

μœ„μΉ˜ μ„€μ • κΈ°μ€€

β€’
static
β€’
relative
β€’
absolute
β€’
fixed
β€’
sticky

static

relative

β€’
초기 μœ„μΉ˜λ₯Ό κΈ°μ€€μœΌλ‘œ μƒλŒ€μ μœΌλ‘œ 배치
β€’
top, bottom, left, right 둜 μ§€μ •ν•œ 길이만큼 초기 μœ„μΉ˜μ—μ„œ 떨어진 μœ„μΉ˜μ— 배치
β€’
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>position : relative;</title> <link rel="stylesheet" href="css/01_relative.css"> </head> <body> <center><h1>position : relative;</h1></center> <div class="container"> <!-- .relative*4{$} --> <div class="relative first">1</div> <div class="relative second">2</div> <div class="relative third">3</div> <div class="relative fourth">4</div> <!-- .absolute*4{$} --> <div class="absolute fifth">1</div> <div class="absolute sixth">2</div> <div class="absolute seventh">3</div> <div class="absolute eighth">4</div> </div> </body> </html>
HTML
볡사
β€’
CSS
h1 { text-align: center; } .container { position: relative; width: 1200px; height: 800px; border: 5px dashed orange; margin: auto; } .container div { margin: auto; width: 200px; height: 200px; box-sizing: border-box; text-align: center; font-size: 48px; line-height: 200px; border-radius: 10%; } /* position : relative; */ .container .relative { position: relative; border: 3px solid black; } /* μ΄ˆκΈ°μœ„μΉ˜ */ .container .absolute { position: absolute; border: 1px dashed #ddd; color: #ddd; z-index: -1; } /* relative */ .first { left: 100px; } .second { right: 100px; } .third { top: 100px; left: 200px; } .fourth { bottom: 100px; right: 200px; } /* absolute */ .fifth { top: 0; left: 500px; } .sixth { top: 200px; left: 500px; } .seventh { top: 400px; left: 500px; } .eighth { top: 600px; left: 500px; }
CSS
볡사

absolute

β€’
λΆ€λͺ¨ μš”μ†Œλ₯Ό κΈ°μ€€μœΌλ‘œ μ ˆλŒ€μ μΈ μœ„μΉ˜λ‘œ 배치
β€’
νŽ˜μ΄μ§€μ˜ 정상적인 νλ¦„μ—μ„œ μ œμ™Έ
β€’
λ‹€λ₯Έ μš”μ†Œμ™€ κ²Ήμ³μ Έμ„œ(over-lap) 배치될 수 있음
β€’
top, bottom, left, right 둜 μ§€μ •ν•œ 길이만큼 λΆ€λͺ¨ μš”μ†Œμ—μ„œ 떨어진 μœ„μΉ˜μ— 배치
β€’
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>position : absolute;</title> <link rel="stylesheet" href="css/02_absolute.css"> </head> <body> <center><h1>position : absolute;</h1></center> <div class="container"> <div class="absolute first">1</div> <div class="absolute second">2</div> <div class="absolute third">3</div> <div class="absolute fourth">4</div> <!-- μ •κ°€μš΄λ° --> <div class="absolute center">CENTER</div> <div class="base fifth">1</div> <div class="base sixth">2</div> <div class="base seventh">3</div> <div class="base eighth">4</div> </div> </body> </html>
HTML
볡사
β€’
CSS
h1 { text-align: center; } .container { position: relative; width: 1200px; height: 800px; border: 5px dashed orange; margin: auto; } .container div { margin: auto; width: 200px; height: 200px; box-sizing: border-box; text-align: center; font-size: 48px; line-height: 200px; border-radius: 10%; } /* position : absolute; */ .container .absolute { position: absolute; border: 3px solid black; } /* μ΄ˆκΈ°μœ„μΉ˜ */ .container .base { position: absolute; border: 1px dashed #ddd; color: #ddd; z-index: -1; } /* absolute */ .first { top: 0; left: 0; } .second { top: 0; right: 0; } .third { bottom: 0; left: 0; } .fourth { bottom: 0; right: 0; } /* base */ .fifth { top: 0; left: 500px; } .sixth { top: 200px; left: 500px; } .seventh { top: 400px; left: 500px; } .eighth { top: 600px; left: 500px; } /* λΆ€λͺ¨μš”μ†Œλ₯Ό κΈ°μ€€μœΌλ‘œ μ •κ°€μš΄λ° */ .center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); /* top, left : % λŠ” λΆ€λͺ¨μš”μ†Œμ— λŒ€ν•œ λΉ„μœ¨ */ /* translate() : % λŠ” ν•΄λ‹Ήμš”μ†Œμ— λŒ€ν•œ λΉ„μœ¨ */ }
CSS
볡사

fixed

β€’
λΈŒλΌμš°μ €(뷰포트)λ₯Ό κΈ°μ€€μœΌλ‘œ μƒλŒ€μ μΈ μœ„μΉ˜λ‘œ 배치
β€’
νŽ˜μ΄μ§€λ₯Ό μŠ€ν¬λ‘€ν•΄λ„ κ³ μ •λœ μœ„μΉ˜λ₯Ό μœ μ§€
β€’
top, bottom, left, right 둜 μ§€μ •ν•œ 길이만큼 νŽ˜μ΄μ§€μ˜ ν…Œλ‘λ¦¬μ—μ„œ 떨어진 μœ„μΉ˜μ— 배치
β€’
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>position : fixed;</title> <link rel="stylesheet" href="css/03_fixed.css"> </head> <body> <center><h1>position : fixed;</h1></center> <div class="container"> <div class="fixed first">1</div> <div class="fixed second">2</div> <div class="fixed third">3</div> <div class="fixed fourth">4</div> <!-- μ •κ°€μš΄λ° --> <div class="fixed center">CENTER</div> <div class="base fifth">1</div> <div class="base sixth">2</div> <div class="base seventh">3</div> <div class="base eighth">4</div> </div> <div style="height: 2000px;"></div> <div class="floating-btn"> λ²„νŠΌ </div> </body> </html>
HTML
볡사
β€’
CSS
h1 { text-align: center; } .container { position: relative; width: 1200px; height: 800px; border: 5px dashed orange; margin: auto; } .container div { margin: auto; width: 200px; height: 200px; box-sizing: border-box; text-align: center; font-size: 48px; line-height: 200px; border-radius: 10%; } /* position : fixed; */ .container .fixed { position: fixed; border: 3px solid black; } /* μ΄ˆκΈ°μœ„μΉ˜ */ .container .base { position: absolute; border: 1px dashed #ddd; color: #ddd; z-index: -1; } /* absolute */ .first { top: 0; left: 0; } .second { top: 0; right: 0; } .third { bottom: 0; left: 0; } .fourth { bottom: 0; right: 0; } /* base */ .fifth { top: 0; left: 500px; } .sixth { top: 200px; left: 500px; } .seventh { top: 400px; left: 500px; } .eighth { top: 600px; left: 500px; } /* λΆ€λͺ¨μš”μ†Œλ₯Ό κΈ°μ€€μœΌλ‘œ μ •κ°€μš΄λ° */ .center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); /* top, left : % λŠ” λΆ€λͺ¨μš”μ†Œμ— λŒ€ν•œ λΉ„μœ¨ */ /* translate() : % λŠ” ν•΄λ‹Ήμš”μ†Œμ— λŒ€ν•œ λΉ„μœ¨ */ } /* ν”Œλ‘œνŒ… λ²„νŠΌ */ .floating-btn { position: fixed; right: 50px; bottom: 250px; background-color: red; border-radius: 50%; width: 100px; height: 100px; line-height: 100px; color: white; text-align: center; font-size: 30px; cursor: pointer; }
CSS
볡사

sticky

β€’
슀크둀 μœ„μΉ˜λ₯Ό κΈ°μ€€μœΌλ‘œ 배치
β€’
슀크둀 μœ„μΉ˜
β€’
νŽ˜μ΄μ§€ μ‹œμž‘~μš”μ†Œμ˜ μœ„μΉ˜ : relative
β€’
κ·Έ 이후 : fixed
β€’
IE μ—μ„œλŠ” μ§€μ›ν•˜μ§€ μ•ŠμŒ
β€’
Safari μ—μ„œλŠ” –webkit- prefix κ°€ ν•„μš”ν•¨
β€’
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>position : sticky;</title> <link rel="stylesheet" href="css/04_sticky.css"> </head> <body> <center><h1>position : sticky;</h1></center> <div class="container"> <div class="box"></div> <header>HEADER</header> <div class="box"></div> <div class="sticky first">1</div> <div class="sticky second">2</div> <div class="sticky third">3</div> <div class="sticky fourth">4</div> <div class="base fifth">1</div> <div class="base sixth">2</div> <div class="base seventh">3</div> <div class="base eighth">4</div> </div> <div style="height: 2000px;"></div> </body> </html>
HTML
볡사
β€’
CSS
h1 { text-align: center; } .container { position: relative; width: 1200px; height: 3000px; border: 5px dashed orange; margin: auto; } .container div { margin: auto; width: 200px; height: 200px; line-height: 200px; box-sizing: border-box; text-align: center; font-size: 48px; border-radius: 10%; } /* position : sticky; */ .container .sticky { position: sticky; border: 3px solid black; } /* μ΄ˆκΈ°μœ„μΉ˜ */ .container .base { position: absolute; border: 3px dashed #ddd; color: #ddd; z-index: -1; } /* 슀크둀 μ˜μ—­ μ•ˆ : relative 슀크둀 μ˜μ—­ λ°– : fixed */ /* sticky */ .first { top: 100px; float: left; } .second { top: 100px; float: left; } .third { top: 100px; float: right; } .fourth { top: 100px; float: right; } /* base */ .fifth { top: 0; left: 500px; } .sixth { top: 200px; left: 500px;} .seventh { top: 400px; left: 500px;} .eighth { top: 600px; left: 500px;} .center { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); /* top, left 의 % λŠ” λΆ€λͺ¨μš”μ†Œμ— λŒ€ν•œ λΉ„μœ¨ */ /* translate() 의 % λŠ” ν•΄λ‹Ήμš”μ†Œμ— λŒ€ν•œ λΉ„μœ¨ */ /* translate( xμΆ•, yμΆ• ) */ } header { position: sticky; top: 0; left: 0; width: 100%; height: 80px; background-color: cornflowerblue; color: white; font-size: 40px; text-align: center; line-height: 80px; } .box { width: 1200px !important; height: 300px !important; margin-top: 80px; border-radius: 0 !important; background-color: royalblue; }
CSS
볡사

κΈ°λ³Έ μ˜ˆμ‹œ μ½”λ“œ

<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>μœ„μΉ˜ 속성 μ˜ˆμ‹œ</title> <style> /* κΈ°λ³Έ μŠ€νƒ€μΌ μ„€μ • */ body { margin: 0; font-family: Arial, sans-serif; height: 100vh; display: flex; justify-content: center; align-items: center; background-color: #f0f0f0; } /* μœ„μΉ˜ 속성 μ˜ˆμ‹œ */ .container { position: relative; width: 200px; height: 200px; background-color: lightblue; } .box { position: absolute; width: 100px; height: 100px; background-color: coral; top: 20px; /* μƒλ‹¨μ—μ„œ 20px μœ„μΉ˜ */ right: 20px; /* μš°μΈ‘μ—μ„œ 20px μœ„μΉ˜ */ z-index: 10; /* μŒ“μž„ μˆœμ„œ, 값이 클수둝 μœ„μ— ν‘œμ‹œλ¨ */ } </style> </head> <body> <div class="container"> <div class="box"></div> </div> </body> </html>
HTML
볡사

μœ„μΉ˜ 속성 ν™œμš©

β€’
μ •κ°€μš΄λ° μœ„μΉ˜ 지정
β€’
κ³ μ • 헀더
β€’
μŠ€ν‹°ν‚€ 헀더
β€’
ν”Œλ‘œνŒ… λ²„νŠΌ

μ •κ°€μš΄λ° μœ„μΉ˜ 지정

λΆ€λͺ¨ μš”μ†Œ λ˜λŠ” λΈŒλΌμš°μ € μš”μ†Œ κΈ°μ€€ κ°€μš΄λ° μœ„μΉ˜ν•˜λ„λ‘ μ„€μ •ν•΄λ΄…λ‹ˆλ‹€.
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>μ •κ°€μš΄λ° μœ„μΉ˜</title> <style> body { margin: 0; height: 100vh; display: flex; justify-content: center; align-items: center; background-color: #f0f0f0; } .centered { width: 200px; height: 100px; background-color: lightcoral; text-align: center; line-height: 100px; color: white; } </style> </head> <body> <div class="centered">쀑앙 μœ„μΉ˜</div> </body> </html>
HTML
볡사

κ³ μ • 헀더

νŽ˜μ΄μ§€λ₯Ό 슀크둀 ν•˜μ—¬λ„, 헀더가 상단에 κ³ μ •λ˜λ„λ‘ ν•©λ‹ˆλ‹€.
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>κ³ μ • 헀더</title> <style> body { margin: 0; font-family: Arial, sans-serif; } header { position: fixed; top: 0; left: 0; width: 100%; background-color: #333; color: white; padding: 15px; text-align: center; z-index: 1000; } .content { margin-top: 60px; /* 헀더 λ†’μ΄λ§ŒνΌ μ—¬λ°± μΆ”κ°€ */ padding: 20px; } </style> </head> <body> <header>κ³ μ • 헀더</header> <div class="content"> <p>μŠ€ν¬λ‘€ν•˜μ—¬ λ‚΄μš©μ„ ν™•μΈν•˜μ„Έμš”.</p> <p>λ§Žμ€ λ‚΄μš©μ΄ λ“€μ–΄κ°€λ©΄ ν—€λ”λŠ” 계속 상단에 κ³ μ •λ©λ‹ˆλ‹€.</p> </div> </body> </html>
HTML
볡사

μŠ€ν‹°ν‚€ 헀더

슀크둀 μ‹œ μŠ€ν‹°μ²˜λŸΌ 달라뢙어 κ³ μ •λ˜λŠ” 헀더λ₯Ό λ§Œλ“€μ–΄λ΄…λ‹ˆλ‹€.
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>μŠ€ν‹°ν‚€ 헀더</title> <style> body { margin: 0; font-family: Arial, sans-serif; } header { position: sticky; top: 0; background-color: #444; color: white; padding: 15px; text-align: center; z-index: 1000; } .content { height: 2000px; /* μΆ©λΆ„ν•œ μŠ€ν¬λ‘€μ„ μœ„ν•΄ 높이 μ„€μ • */ padding: 20px; } </style> </head> <body> <header>μŠ€ν‹°ν‚€ 헀더</header> <div class="content"> <p>μŠ€ν¬λ‘€ν•˜μ—¬ ν—€λ”μ˜ μŠ€ν‹°ν‚€ 효과λ₯Ό ν™•μΈν•˜μ„Έμš”.</p> </div> </body> </html>
HTML
볡사

ν”Œλ‘œνŒ… λ²„νŠΌ

헀이지 우츑 ν•˜λ‹¨μ— λ– μžˆλŠ” λ²„νŠΌμ„ λ§Œλ“€μ–΄λ΄…λ‹ˆλ‹€.
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ν”Œλ‘œνŒ… λ²„νŠΌ</title> <style> body { margin: 0; font-family: Arial, sans-serif; } .floating-button { position: fixed; bottom: 20px; right: 20px; width: 60px; height: 60px; background-color: #007bff; color: white; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 24px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); cursor: pointer; } </style> </head> <body> <div class="floating-button">+</div> </body> </html>
HTML
볡사
μŠ€νƒ€μΌ 속성
μŠ€νƒ€μΌ 속성