๋ฐฐ๊ฒฝ ์์ฑ
๋ฐฐ๊ฒฝ์ ์ ์ดํ๋ ์์ฑ
โข
๋ฐฐ๊ฒฝ ์์ฑ ์ข
๋ฅ
โข
๋ฐฐ๊ฒฝ ๊ทธ๋ผ๋ฐ์ด์
ํจ์
โข
๊ธฐ๋ณธ ์์ ์ฝ๋
โข
๋ฐฐ๊ฒฝ ์์ฑ ์์ฉ
โฆ
๋ฐฐ๊ฒฝ ๊ณ ์ ์คํฌ๋กค
โฆ
ํ
์คํธ ๋ง์คํฌ
โฆ
์ด๋ฏธ์ง ๋ง์คํฌ
๋ฐฐ๊ฒฝ ์์ฑ ์ข ๋ฅ
์์ฑ | ์ค๋ช
|
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
๋ณต์ฌ