기본 소스와 결과

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
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body{
            margin: 0px;
            padding: 0px;
        }
        div{
            width: 100px;
            height: 100px;
        }
        div:nth-child(1){
            background-color: lightpink;
        }
        div:nth-child(2){
            background-color: lightgreen;
        }
        div:nth-child(3){
            background-color: lightgray;
        }
        div:nth-child(4){
            background-color: lightyellow;
        }
        div:nth-child(5){
            background-color: lightblue;
        }
    </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
</body>
</html>
cs


1번 : 왼쪽으로 300px 만큼 이동

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
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body{
            margin: 0px;
            padding: 0px;
        }
        div{
            width: 100px;
            height: 100px;
        }
        div:nth-child(1){
            background-color: lightpink;
            margin-left: 300px;
        }
        div:nth-child(2){
            background-color: lightgreen;
            position: static;    /*디폴트값*/
        }
        div:nth-child(3){
            background-color: lightgray;
        }
        div:nth-child(4){
            background-color: lightyellow;
        }
        div:nth-child(5){
            background-color: lightblue;
        }
    </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
</body>
</html>
cs

결과

2번 : position 의 디폴트 값으로 설정(변화없음)

3번 : position 의 절대 값으로 설정

소스

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body{
            margin: 0px;
            padding: 0px;
        }
        div{
            width: 100px;
            height: 100px;
        }
        div:nth-child(1){
            background-color: lightpink;
            margin-left: 300px;
        }
        div:nth-child(2){
            background-color: lightgreen;
            position: static;    /*디폴트값*/
        }
        div:nth-child(3){
            background-color: lightgray;
            position: absolute;    /*절대값으로 위치를 설정*/
            left: 300px;    /* x축 */
            top: 400px;    /* y축 (작성하지 않는다면 원래의 위치로 설정됨 */
        }
        div:nth-child(4){
            background-color: lightyellow;
        }
        div:nth-child(5){
            background-color: lightblue;
        }
    </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
</body>
</html>
cs

결과

4번 : 변경사항없음

5번 : position 의 상대 값으로 설정

소스

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body{
            margin: 0px;
            padding: 0px;
        }
        div{
            width: 100px;
            height: 100px;
        }
        div:nth-child(1){
            background-color: lightpink;
            margin-left: 300px;
        }
        div:nth-child(2){
            background-color: lightgreen;
            position: static;    /*디폴트값*/
        }
        div:nth-child(3){
            background-color: lightgray;
            position: absolute;    /*절대값으로 위치를 설정*/
            left: 300px;    /* x축 */
            top: 400px;    /* y축 (작성하지 않는다면 원래의 위치로 설정됨 */
        }
        div:nth-child(4){
            background-color: lightyellow;
        }
        div:nth-child(5){
            background-color: lightblue;
            position: relative;    /*상대좌표로서 원래위치에서 변경*/
            left: 50px;
            top: 50px;
        }
    </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
</body>
</html>
cs

결과



소스

* position: fixed; 가 고정하는 기능을 한다.

* background-repeat: no-repeat; 는 이미지의 중복되는 것을 막아준다.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body{
            margin: 0px;
            padding: 0px;
        }
        #bar{
            border: 1px red solid;
        }
        img{
            width: auto;
            height: 80px;
        }
        #img01{
            position: fixed;
            background-color: aquamarine;
            width: 100%;
            height: 250px;
            background-image: url(uuu.jpg);
            /*background-size: 50%;*/
            background-repeat: no-repeat;
            /*background-attachment: fixed;*/
        }
    </style>
</head>
<body>
<!--    <img alt="" src="googlelogo.png" />
    <div id="bar"> </div>-->
    <div id="img01">다음의 이미지는 로고</div>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/>
</body>
</html>
cs


결과

스크롤을 내려도 따라오는것을 알수있다.


+ Recent posts