Search

๋ฐฐ๊ฒฝ ์†์„ฑ

๋ฐฐ๊ฒฝ ์†์„ฑ

๋ฐฐ๊ฒฝ์„ ์ œ์–ดํ•˜๋Š” ์†์„ฑ
โ€ข
๋ฐฐ๊ฒฝ ์†์„ฑ ์ข…๋ฅ˜
โ€ข
๋ฐฐ๊ฒฝ ๊ทธ๋ผ๋ฐ์ด์…˜ ํ•จ์ˆ˜
โ€ข
๊ธฐ๋ณธ ์˜ˆ์‹œ ์ฝ”๋“œ
โ€ข
๋ฐฐ๊ฒฝ ์†์„ฑ ์‘์šฉ
โ—ฆ
๋ฐฐ๊ฒฝ ๊ณ ์ • ์Šคํฌ๋กค
โ—ฆ
ํ…์ŠคํŠธ ๋งˆ์Šคํฌ
โ—ฆ
์ด๋ฏธ์ง€ ๋งˆ์Šคํฌ

๋ฐฐ๊ฒฝ ์†์„ฑ ์ข…๋ฅ˜

์†์„ฑ
์„ค๋ช…
background-color
๋ฐฐ๊ฒฝ์ƒ‰์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
background-image
๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
background-repeat
๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜๋ณตํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
background-position
๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ์œ„์น˜๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
background-size
๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
background-attachment
๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ์Šคํฌ๋กค ๋™์ž‘์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
background
์œ„์˜ ๋ชจ๋“  ๋ฐฐ๊ฒฝ ์†์„ฑ์„ ํ•œ ๋ฒˆ์— ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐฐ๊ฒฝ ๊ทธ๋ผ๋ฐ์ด์…˜ ํ•จ์ˆ˜

ํ•จ์ˆ˜
์„ค๋ช…
์ฃผ์š” ์†์„ฑ
linear-gradient
์„ ํ˜• ๊ทธ๋ผ๋ฐ์ด์…˜
direction (๊ฐ๋„, ๋ฐฉํ–ฅ), color-stop (์ƒ‰์ƒ ๋ฐ ์œ„์น˜)
radial-gradient
๋ฐฉ์‚ฌํ˜• ๊ทธ๋ผ๋ฐ์ด์…˜
shape (์›ํ˜•, ํƒ€์›ํ˜•), size (ํฌ๊ธฐ), position (์œ„์น˜), color-stop (์ƒ‰์ƒ ๋ฐ ์œ„์น˜)
conic-gradient
์›๋ฟ”ํ˜• ๊ทธ๋ผ๋ฐ์…˜
from angle (์‹œ์ž‘ ๊ฐ๋„), at position (์ค‘์‹ฌ ์œ„์น˜), color-stop (์ƒ‰์ƒ ๋ฐ ์œ„์น˜)

linear-gradient ํ•จ์ˆ˜

โ€ข
๊ธฐ๋ณธ ๊ตฌ๋ฌธ: linear-gradient(direction, color-stop1, color-stop2, ...)
โ—ฆ
direction: ๊ทธ๋ผ๋ฐ์ด์…˜์˜ ๋ฐฉํ–ฅ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ๋„(์˜ˆ: 45deg)๋‚˜ ๋ฐฉํ–ฅ ํ‚ค์›Œ๋“œ(์˜ˆ: to right, to bottom)๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
โ—ฆ
color-stop: ๊ทธ๋ผ๋ฐ์ด์…˜์˜ ์ƒ‰์ƒ๊ณผ ์œ„์น˜๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ƒ‰์ƒ๊ฐ’๊ณผ ์œ„์น˜(์˜ˆ: #ff0000 0%, #0000ff 100%)๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

radial-gradient ํ•จ์ˆ˜

โ€ข
๊ธฐ๋ณธ ๊ตฌ๋ฌธ: radial-gradient(shape size at position, color-stop1, color-stop2, ...)
โ—ฆ
shape: ๊ทธ๋ผ๋ฐ์ด์…˜์˜ ํ˜•ํƒœ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์›ํ˜•(circle) ๋˜๋Š” ํƒ€์›ํ˜•(ellipse)์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
โ—ฆ
size: ๊ทธ๋ผ๋ฐ์ด์…˜์˜ ํฌ๊ธฐ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ํฌ๊ธฐ(farthest-corner, closest-side, ๋“ฑ) ๋˜๋Š” ์‚ฌ์šฉ์ž ์ •์˜ ํฌ๊ธฐ(50%, 20px ๋“ฑ)๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
โ—ฆ
position: ๊ทธ๋ผ๋ฐ์ด์…˜์˜ ์‹œ์ž‘ ์œ„์น˜๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์œ„์น˜ ํ‚ค์›Œ๋“œ(์˜ˆ: center, top left) ๋˜๋Š” ์ขŒํ‘œ(์˜ˆ: 50% 50%)๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
โ—ฆ
color-stop: ์ƒ‰์ƒ๊ณผ ์œ„์น˜๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

conic-gradient ํ•จ์ˆ˜

โ€ข
๊ธฐ๋ณธ ๊ตฌ๋ฌธ: conic-gradient(from angle at position, color-stop1, color-stop2, ...)
โ—ฆ
from angle: ๊ทธ๋ผ๋ฐ์ด์…˜์˜ ์‹œ์ž‘ ๊ฐ๋„๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ 0deg์ด๋ฉฐ, ์‹œ๊ณ„ ๋ฐฉํ–ฅ์œผ๋กœ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
โ—ฆ
at position: ๊ทธ๋ผ๋ฐ์ด์…˜์˜ ์ค‘์‹ฌ ์œ„์น˜๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์œ„์น˜ ํ‚ค์›Œ๋“œ(์˜ˆ: center) ๋˜๋Š” ์ขŒํ‘œ(์˜ˆ: 50% 50%)๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
โ—ฆ
color-stop: ์ƒ‰์ƒ๊ณผ ์œ„์น˜๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์˜ˆ์‹œ ์ฝ”๋“œ

์‹ฌํ”Œ ์˜ˆ์‹œ

<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>๋ฐฐ๊ฒฝ ์†์„ฑ ์˜ˆ์‹œ</title> <style> .background-example { background-color: lightblue; background-image: url('background.jpg'); background-repeat: no-repeat; background-position: center; background-size: cover; background-attachment: fixed; } </style> </head> <body> <div class="background-example"> <h1>๋ฐฐ๊ฒฝ ์†์„ฑ ์˜ˆ์‹œ</h1> <p>์ด ์˜์—ญ์—๋Š” ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์™€ ์ƒ‰์ƒ์ด ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.</p> </div> </body> </html>
HTML
๋ณต์‚ฌ

๋ชจ๋“  ๋ฐฐ๊ฒฝ ์†์„ฑ ์ ์šฉ ์˜ˆ์‹œ

โ€ข
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>background</title> <link rel="stylesheet" href="css/01_๊ธฐ๋ณธ๋ฐฐ๊ฒฝ.css"> </head> <body> <div class="container"> <h1>My Room</h1> <h2>background</h2> <div class="inner back1"></div> <hr> <!-- background-repeat --> <h2>background-repeat: repeat-x;</h2> <div class="inner back2"></div> <hr> <h2>background-repeat: repeat-y;</h2> <div class="inner back3"></div> <hr> <h2>background-repeat: no-repeat;</h2> <div class="inner back4"></div> <hr> <!-- background-position --> <h2>background-position: left;</h2> <div class="inner back1 left"></div> <hr> <h2>background-position: center;</h2> <div class="inner back1 center"></div> <hr> <h2>background-position: right;</h2> <div class="inner back1 right"></div> <hr> <h2>background-position: top left;</h2> <div class="inner back1 top-left"></div> <hr> <h2>background-position: top right;</h2> <div class="inner back1 top-right"></div> <hr> <h2>background-position: bottom left;</h2> <div class="inner back1 bottom-left"></div> <hr> <h2>background-position: bottom right;</h2> <div class="inner back1 bottom-right"></div> <hr> <h2>background-position: top center;</h2> <div class="inner back1 top-center"></div> <hr> <h2>background-position: center center;</h2> <div class="inner back1 center-center"></div> <hr> <h2>background-position: bottom center;</h2> <div class="inner back1 bottom-center"></div> <hr> <h2>background-color: mediumspringgreen</h2> <div class="inner back4 mint"></div> <h2>multi-back</h2> <div class="inner classroom"></div> <h2>multi-back</h2> <div class="inner short"></div> </div> </body> </html>
HTML
๋ณต์‚ฌ
โ€ข
CSS
.container { text-align: center; } .inner { width: 70vw; /* ๋ณด์—ฌ์ง€๋Š” ๊ฐ€๋กœ์˜์—ญ์˜ 70% ๋น„์œจ๋กœ ์ ์šฉ */ min-height: 70vh; /* ๋ณด์—ฌ์ง€๋Š” ์„ธ๋กœ์˜์—ญ์˜ 70% ๋น„์œจ๋กœ ์ ์šฉ */ margin: 0 auto; border: 1px solid gray; } /* background-image */ .back1 { background-image: url(../img/aloha.png); } /* background-size, background-repeat */ .back2 { min-height: 190px; background-image: url(../img/aloha.png); background-size: 200px 190px; /* ๊ฐ€๋กœ ์„ธ๋กœ */ background-repeat: repeat-x; /* x์ถ•์œผ๋กœ๋งŒ ์ด๋ฏธ์ง€ ๋ฐ˜๋ณต */ } .back3 { min-height: 600px; background-image: url(../img/aloha.png); background-size: 200px; background-repeat: repeat-y; /* y์ถ•์œผ๋กœ๋งŒ ์ด๋ฏธ์ง€ ๋ฐ˜๋ณต */ } .back4 { background-image: url(../img/aloha.png); background-repeat: no-repeat; } /* background-position */ .left { background-repeat: no-repeat; background-position: left; } .center { background-repeat: no-repeat; background-position: center; } .right { background-repeat: no-repeat; background-position: right; } .top-left { background-size: 200px 190px; background-repeat: no-repeat; background-position: top left; } .top-right { background-size: 200px 190px; background-repeat: no-repeat; background-position: top right; } .bottom-left { background-size: 200px 190px; background-repeat: no-repeat; background-position: bottom left; } .bottom-right { background-size: 200px 190px; background-repeat: no-repeat; background-position: bottom right; } .top-center { background-size: 200px 190px; background-repeat: no-repeat; background-position: top center; } .center-center { background-size: 200px 190px; background-repeat: no-repeat; background-position: center center; } .bottom-center { background-size: 200px 190px; background-repeat: no-repeat; background-position: bottom center; } body { background-image: url(../img/aloha.png); background-size: 200px 190px; background-position: top right; background-repeat: no-repeat; background-attachment: fixed; /* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ๊ณ ์ • */ } .mint { background-color: mediumspringgreen; } /* ์ด๋ฏธ์ง€๋ฅผ 2๊ฐœ์ด์ƒ ์ ์šฉ : (,) ๊ธฐํ˜ธ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์†์„ฑ๊ฐ’์„ ์‚ฌ์šฉ */ /* background-size - px : (width height) - cover : ์ด๋ฏธ์ง€๋ฅผ ํ™•๋Œ€/์ถ•์†Œํ•ด์„œ ๋ฐ•์Šค ๊ฐ€๋กœ ๋˜๋Š” ์„ธ๋กœ ํฌ๊ธฐ์— ๋”ฑ ๋งž๊ฒŒ ์ฑ„์›€ - contain : ์ด๋ฏธ์ง€ ์ „์ฒด๊ฐ€ ๋ณด์ด๋„๋ก, ๊ฐ€๋กœ/์„ธ๋กœ ๋น„์œจ์„ ์œ ์ง€ํ•˜์—ฌ ํฌ๊ธฐ ์กฐ์ • */ .classroom { background-image: url(../img/aloha.png), url(../img/classroom.jpg); background-size: contain, cover; background-repeat: no-repeat, no-repeat; background-position: left, center; } /* background ๋‹จ์ถ• ์†์„ฑ - background-color - background-image - background-repeat - background-attachment - background-position / background-size * ์ค‘๊ฐ„์˜ ๊ฐœ๋ณ„์†์„ฑ ๊ฐ’์ด ๋ˆ„๋ฝ๋˜์–ด๋„ ์ ์šฉ๊ฐ€๋Šฅ */ .short { background: url(../img/aloha.png) no-repeat scroll left bottom / contain, url(../img/classroom.jpg) no-repeat scroll center center / cover; }
CSS
๋ณต์‚ฌ

๋ฐฐ๊ฒฝ ์†์„ฑ ์‘์šฉ

โ€ข
๋ฐฐ๊ฒฝ ๊ณ ์ • ์Šคํฌ๋กค
โ€ข
ํ…์ŠคํŠธ ๋งˆ์Šคํฌ
โ€ข
์ด๋ฏธ์ง€ ๋งˆ์Šคํฌ

๋ฐฐ๊ฒฝ ๊ณ ์ • ์Šคํฌ๋กค

โ€ข
HTML
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>๋ฐฐ๊ฒฝ ์†์„ฑ ์˜ˆ์‹œ</title> <link rel="stylesheet" href="css/02_๊ณ ์ •๋ฐฐ๊ฒฝ์Šคํฌ๋กค.css"> </head> <body> <div class="background-example"> <div class="content"> ALOHA <br> COFFEE SHOP </div> </div> </body> </html>
HTML
๋ณต์‚ฌ
โ€ข
CSS
* { margin: 0; padding: 0; box-sizing: border-box; } .background-example { background-color: lightblue; background-image: url('img/background.jpg'); background-repeat: no-repeat; background-position: center; background-size: cover; background-attachment: fixed; margin: 800px auto; height: 600px; color: white; } .content { font-size: 200px; margin: 0 auto; text-align: center; }
CSS
๋ณต์‚ฌ

ํ…์ŠคํŠธ ๋งˆ์Šคํฌ

โ€ข
HTML
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ํ…์ŠคํŠธ ๋งˆ์Šคํฌ</title> <link rel="stylesheet" href="css/03_ํ…์ŠคํŠธ๋งˆ์Šคํฌ.css"> </head> <body> <div class="wrapper"> <div class="background-example"> ALOHA <br> COFFEE SHOP </div> </div> </body> </html>
HTML
๋ณต์‚ฌ
โ€ข
CSS
* { margin: 0; padding: 0; box-sizing: border-box; } .background-example { background-color: lightblue; background-image: url('img/background.jpg'); background-repeat: no-repeat; background-position: center; background-size: cover; background-attachment: fixed; margin: 800px auto; height: 800px; color: white; background-clip: text; -webkit-background-clip: text; color: transparent; text-align: center; padding: 50px; font-size: 200px; font-weight: bold; } /* .wrapper { background-color: black; } */
CSS
๋ณต์‚ฌ

์ด๋ฏธ์ง€ ๋งˆ์Šคํฌ

โ€ข
HTML
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>์ด๋ฏธ์ง€ ๋งˆ์Šคํฌ</title> <link rel="stylesheet" href="css/04_์ด๋ฏธ์ง€๋งˆ์Šคํฌ.css"> </head> <body> <div class="wrapper"> <div class="mask star"></div> <div class="mask heart"></div> <div class="mask circle"></div> <div class="mask message"></div> </div> </body> </html>
HTML
๋ณต์‚ฌ
โ€ข
CSS
/* ์ „์ฒด ํŽ˜์ด์ง€ ์Šคํƒ€์ผ */ body { margin: 0; font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f0f0; } /* ์ปจํ…Œ์ด๋„ˆ ์Šคํƒ€์ผ */ .wrapper { display: flex; justify-content: center; align-items: center; height: 100%; width: 100%; gap: 50px; } /* ์ด๋ฏธ์ง€ ๋งˆ์Šคํฌ ์ ์šฉ */ .mask { width: 300px; height: 300px; background-image: url('../img/background.jpg'); background-size: cover; background-position: center; background-repeat: no-repeat; } .star { clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); } .heart { clip-path: polygon(50% 15%, 79% 0, 100% 35%, 91% 64%, 74% 84%, 50% 100%, 28% 83%, 11% 65%, 0% 35%, 20% 0); } .circle { clip-path: circle(50% at 50% 50%); } .message { clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%); }
CSS
๋ณต์‚ฌ
์Šคํƒ€์ผ ์†์„ฑ
์Šคํƒ€์ผ ์†์„ฑ