[CSS] position

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 <style>
        #static,#relative,#absolute,#fixed{
            width: 100px;
            height: 100px;
        }
        #static{
            background-color: red;
            /* 
            position : static
            위에서 아래로 배치, 위치 속성 비활성화
            position의 기본 값
            */
            position: static;
            top : 20px;
            left : 20px;
        }
        #relative{
            background-color: black;
            /* 
            position : relative
            위치 속성 활성화, 기준에서 설정된 위치로 설정됨
            기준 : 본인이 원래 있었던 위치
            */
            position: relative;
            top : 20px;
            left : 20px;
        }
        #parents{
            position : relative;
        }
        #absolute{
            background-color: purple;
            /* 
            position : absolute
            위치 속성 활성화
            기준 : position 이 static이 아닌 부모
            없을 경우 : body 태그를 기준으로 삼는다.
            */
            position: absolute;
            top : 0px;
            left : 20px;
        }
        /* 부모 신경 X, body 태그 내에서 고정 */
        #fixed{
            background-color: blue;
            
            /* position fixed
            -위치 속성 활성화
            -기준 : body 태그를 기준으로 삼는다.
            -scroll 또한 무시
            -화면의 설정된 위치에 항상 고정
            */
            position: fixed;
            top : 10px;
            left: 10px;
            
        }
 
    </style>
</head>
<body>
    body 태그 안입니다
    <div id = "parents">
        parents 안 입니다
        <div id = "static"></div>
        <div id = "relative"> </div>
        <div id = "absolute"></div>
 
    /*fixed 태그 시험용 개행 */
        <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>
        <div id = "fixed"></div>
 
    </div>
</body>
cs


※전체 수행 결과

-각 개체가 겹치는 현상 발생









※ 수행 결과에 대한 탐구

position의 각 속성인 fixed, absolute, relative, static에 따라 표기되는 개체의 위치가 다르다

-position 옵션 계층 표현

기본 값인 static 이 적용된 개체와, fixed 가 적용된 개체의 위치가 같다면,

static 의 위로 fixed 개체가 올라오게 된다.


댓글