donaricano-btn

고정 <header>, <footer> 만들기


1. 구현

1) body

1
2
3
4
body{
     margin-top : 120px;
     margin-bottom:120px;
 }

- body의 위, 아래의 margin 값으로 header와 footer를 고정 시킬 여백의 공간을 만든다

2) <header>

1
2
3
4
5
6
7
8
9
10
header{
       border : 4px solid brown;
       position : fixed;
       left : 0;
       top : 0;
       width: 100%;
       height:100px;
       background-color: antiquewhite;
       z-index: 4;
   }
 

- position: fixed로 고정한다

- z-index : 속성으로 태그들 가장 앞에 배치 하도록 한다.(제대로 동작 안 할 시 추가)

3) <footer>

1
2
3
4
5
6
7
8
9
footer{
       border : 4px solid brown;
       position : fixed;
       left:0;
       bottom : 0;
       width: 100%;
       height:100px;
       background-color:antiquewhite;
   }
 

4) fullSource

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
<!DOCTYPE html>
 
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin-top : 120px;
            margin-bottom:120px;
        }
        footer{
            border : 4px solid brown;
            position : fixed;
            left:0;
            bottom : 0;
            width: 100%;
            height:100px;
            background-color:antiquewhite;
        }
        header{
            border : 4px solid brown;
            position : fixed;
            left : 0;
            top : 0;
            width: 100%;
            height:100px;
            background-color: antiquewhite;
            z-index: 4;
        }
 
    </style>
</head>
 
<header>
    This is a header
</header>
<footer>
    This is a footer
</footer>
 

5) 화면


블로그 이미지

리딩리드

,