기본 소스와 결과

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

결과



+ Recent posts