WEB/CSS

[웹 프로그래밍] WEB 레이아웃 이해하기

현더미 2014. 5. 23. 19:24

 

1_RAYOUT

●요소 위치 정하기


*정적 위치 설정(static positioning)

:: 정상적인 흐름에 따른 배치이다.

*상대 위치 설정(relative positioning)

:: 정상적인 위치가 기준점이 된다.

*절대 위치 설정(absolute positioning)

:: 컨테이너의 원점이 기준점이 된다.

*고정 위치 설정(fixed positioning)

:: 고정된 자리에 위치한다.

 

 -EX

 

 

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
    #one{
        background-color: #008299;
        width: 200px;
        height: 50px;
}
    #two{
        position: static; 
        /*정적 위치 설정
         (여기서는 position을 static으로 선언하면 문서의 정상적인 흐름에 따라서 배치된다
         static으로 선언하지 않은 것과 결과는 같다.)*/ 
        background-color: #FAED7D;
        width:200px;
        height: 50px;
    }
    #three{
        position : relative;
        left : 30px; 
        /*상대 위치 설정
         (정상적인 위치에서 왼쪽으로 30픽셀 이동)*/
        background-color: #99004C;
        width:200px;
        height:50px;
    }
    #four{
        position: absolute;
        /*절대 위치 설정*/
        top: 100px;
        left : 100px;
        background-color: gray;
        width:200px;
        height:50px;
    }
    #five{
        background-color: #F361A6;
        position: fixed;
        /*고정 위치 설정*/
        top:0px;
        right:0px;
    }
</style>
</head>
<body>
<p id="one">Block #1</p>
<div id="two">Block #2<br/>position:static;</div>
<br/>
<div id="three">Block #3<br/>position:relative;<br/>left:30px;</div><br/>
<div id="four">Block #4<br/>position:absolute;
            <br/>top:100px; left:100px;</div>
<div id="five">Block #5<br/>position:fixed;<br/>top:0px; right:0px;</div> 
</body>
 
</html>

 

 

 

 

 

##block #5가 고정된 위치에서 따라 움직이는 것을 볼 수 있다.