소스

* 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


결과

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


소스


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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
    <meta>
    <style>
        table{
            width: 100%;
        }
        tr:first-child{
            background-color: darkgray;
        }
        tr:nth-child(2n){    /*짝수*/
            background-color: beige;
        }
        tr>th:nth-child(1){
            width: 10%;
        }
        tr>th:nth-child(2){
            width: 60%;
        }
        tr>th:nth-child(3){
            width: 20%;
        }
        td>a{
            display: inline-block;
            width: 100%;
            text-decoration: none;
            color: black;
        }
        .line:hover{
            background-color: darksalmon;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <th>1열</th>
            <th>2열</th>
            <th>3열</th>
            <th>4열</th>
        </tr>
        <tr class="line">
            <td><a href="#">1줄</a></td>
            <td><a href="#">1</a></td>
            <td><a href="#">2</a></td>
            <td><a href="#">3</a></td>
        </tr>
        <tr class="line">
            <td>2줄</td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr class="line">
            <td>3줄</td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr class="line">
            <td>4줄</td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr class="line">
            <td>5줄</td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr class="line">
            <td>6줄</td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr class="line">
            <td>7줄</td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr class="line">
            <td>8줄</td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr class="line">
            <td>9줄</td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
    </table>
</body>
</html>
cs


결과

마우스를 올리고 있는 경우


소스


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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <style>
        *{
            padding: 0px;
            margin: 0px;
        }
        div{
            width: 100px;
            height: 100px;
        }
        /*띄어쓰기는 자식을 포함한 모든 자식들에게 적용 / 콤마는(,) 자신까지 */
        body div{
            border-bottom-color: black;
            border-width: 1px;
            border-style: solid;
        }
        body>div>div{
            width: 50px;
            height: 50px;
            background-color: antiquewhite;
        }
        body>div>div>div{
            width: 30px;
            height: 30px;
            background-color: aquamarine;
        }
        /*차이점 확인하기 첫번째 자식한테만 해당*/
        body>div>div:first-child{
            background-color: blueviolet;
        }
        body>div:last-child{
            background-color: fuchsia;
        }
        
    </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>
        <div>4</div>
    </div>
    <div>  
        <div>
            <div>5</div>
        </div>
    </div>
    
</body>
</html>
cs


결과



* 우선순위 알기

우선순위가 높은 것 부터 나열

 인라인(<div style=""> : 사용하지않는게 좋다) > id(#) > 선택자(:) > class(.) > 태그지시자 ( 우선순위가 같다면 오버라이드 )


소스


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
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <style>
        body{
            margin: 0px;
            padding: 10px;
        }
        #logo{
            width: auto;
            height: 80px;
        }
        #main{
            width: 100%;
            height: auto;
        }
        #page1{
            width: 80%;
            margin: auto;
        }
        #content,#aside{
            display: inline-block;
            padding: 0px;
            border-width: 0px;
            margin: 0px;
        }
        #content{
            margin: 5px;
            width: 80%;
        }
        #aside{
            width: 8%;
        }
        ul{
            padding: 0px;
            width: 500px;
            margin: auto;
        }
        li{
            display: inline-block;
            width: 100px;
            background-color: azure;
            margin: 10px;
        }
        #menu{
            background-color: cornsilk;
        }
        a{
            display: inline-block;
            width: 100px;
            height: 30px;
            text-align: center;
            text-decoration: none;
            color: black;
        }
        a:hover{
            background-color: cornflowerblue;
            color: white;
        }
    </style>
</head>
<body>
  <div id="page1">
       <div id="header">
           <img id="logo" alt="" src="googlelogo.png" />
       </div>
       <div id="menu">
           <ul>
               <li><a href="#">menu1</a></li>
               <li><a href="#">menu2</a></li>
               <li><a href="#">menu3</a></li>
               <li><a href="#">menu4</a></li>
           </ul>
       </div>
       <div>
           <div id="content">
               <img id="main" alt="" src="jung.png"/>
           </div>
            <div id="aside">
               광고란
           </div>
       </div>
       <div id="footer">
           오픈 API | 이용약관 | 개인정보취급방침 | 청소년보호정책 | 권리침해신고 | 고객센터 | E-mail수집거부정책
           <br/> Copyright © Kakao Corp. All rights reserved.
        </div>
   </div>
</body>
</html>
cs


결과



*참고 , 이미지파일은 같은 폴더 내에 가지고 있으면 된다.


소스

* margin / padding / border

현재 소스에서 body 에 마진을 50px 만큼 준것을 표현한 그림이다.

보더에 색을 주고 스타일로 solid를 설정하여 실선으로 표현됨을 알수있다. width에 10px만큼의 두께를 설정한다.

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body{
            margin: 50px;
        }
        h1{
            background-color: red;
            height: 50px;
            /*  width: 200px; 사이즈가 줄은 것 같이 보여도 한 블록을 차지하는건 이전과 동일하다. */
            margin: 0px;
            padding: 0px;
            /* 바디에 마진이 존재한다. */
        }
        p{
            background-color: orange;
            border-color: lightseagreen;
            border-width: 10px; /* 개발자도구의 border과 동일하다. 마진은 위랑 아래랑 그 갭 */
            border-style: solid;
            margin: 0px;
        }
        div{
            background-color: fuchsia; /* 아래에서 오버라이드 되어 적용이 안됨*/
        }
        
        #box1{
            background-color: #0000ff; /* 색깔이 조금씩 더 어둡게 색상 설정 */
            color: white;
        }
        #box2{
            background-color: #0000aa; 
            color: white;
        }
        #box3{
            background-color: #000099;
            color: white;
        }
        #box4{
            background-color: #000055;
            color: white;
        }
        /* 패딩은 텍스트와 보더 전까지의 살짝있는 공간 */
    </style>
</head>
 
<body>
    <h1>head1</h1>
    <h1>head2</h1>
    
    <p>aaaaaaaaaaaaaa</p>
    <p>bbbbbbbbbbbbbb</p>
    
    <div id='box1'>1</div>
    <div id='box2'>2</div>
    <div id='box3'>3</div>
    <div id='box4'>4</div>  
        
</body>
</html>
cs

* 마진 표현  margin: 0px 0px 0px 0px;  이러한 방식으로도 가능 (위 오른 아래 왼  순서)

결과


+ Recent posts