- 배경에 색을 칠할까, 이미지로 그릴까? background-color, background-image
* 배경색을 먼저 칠하고, 배경이미지를 배치하므로, 배경 이미지가 출력 되지 않는 영역에만 배경색이 보인다.

1
2
3
4
div {
    background-color : skyblue;
    background-image : url("media/spongebob.png");
}
cs


- 배경 이미지의 위치, background-position


left top(디폴트), left center, left bottom

right top, right bottom

center top, center center, center bottom

 

1
2
3
div {
    background-position : center center; /* 박스 중간에 이미지 */
}
cs



- 배경 이미지의 크기, background-position

1
2
3
4
5
div {
    background-size : 100px 100px; /* 100 X 100크기로 출력 */
}
 
 
cs



- 배경 이미지 반복 출력, background-repeat


no-repeat, repreat(디폴트), repeat-x, repeat-y


1
2
3
div {
    background-repeat : repeat-y; /* background-position에 지정된 위치에서 이미지를 위해서, 수직 방향으로 반복 출력 */
}
cs


그림 4-22

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>배경 꾸미기</title>
<style>
div {
    background-color: skyblue;
    background-size: 100px 100px;
    background-image: url("media/spongebob.png");
       background-repeat: no-repeat;
    background-position: left center;
}
div {
    width : 200px;
    height : 200px;
    color: blueviolet;
    font-size : 16px;
}
</style>
</head>
<body>
<h3>배경 꾸미기</h3>
<hr>
<div>SpongeBob is an over-optimistic
 sponge that annoys other characters. </div>
</body>
</html>
 
cs




그림 4-23

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>배경 꾸미기</title>
<style>
div {
    background-color: skyblue;
    background-size: 100px 100px;
    background-image: url("media/spongebob.png")
background-repeat: repeat-y;
    background-position: center center;
}
div {
    width : 200px;
    height : 200px;
    color: blueviolet;
    font-size : 16px;
}
</style>
</head>
<body>
<h3>배경 꾸미기</h3>
<hr>
<div>SpongeBob is an over-optimistic
 sponge that annoys other characters. </div>
</body>
</html>
 
cs

- background 단축 프로퍼티

color, image, position/size, repeat, origin 순으로 값 설정

1
2
3
div { color image position/size repeat
    background : skyblue url("media/spongebob.png") center center/100px 100px repeat-y;
}
cs


* background 프로퍼티에는 배경색이나 배경 이미지만 지정할 수있다.


1
2
background : skyblue; /* 배경색을 skyblue로 설정 */
background : url("media/spongebob.png")/* 배경 이미지 지정 */
cs


예제 4-18

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>배경 꾸미기</title>
<style>
div {
    background-color : skyblue;
    background-size : 100px 100px;
    background-image : url("media/spongebob.png");
       background-repeat : repeat-y;
    background-position : center center;
}
div {
    width : 200px;
    height : 200px;
    color : blueviolet;
    font-size : 16px;
}
</style>
</head>
<body>
<h3>div 박스에 배경 꾸미기</h3>
<hr>
<div>SpongeBob is an over-optimistic
 sponge that annoys other characters. </div>
</body>
</html>
 
cs







Posted by 너래쟁이
: