SyntaxHighlighter.all(); 'HTML5 & CSS3' 카테고리의 글 목록 :: 게을러지고 싶어 부지런한 개발자

글꼴 및 폰트 사이즈 관련 속성 

*font-family: 글꼴

  -여러 개 넣을 수 있는데, 제일 첫번째 지정한 폰트를 쓰되, 만약 컴퓨터에 해당 글꼴이 없으면 다음번 지정한 글꼴을 찾아 지정. 모두 없다면 디폴트 서체로 지정됨. 

*font-size: 글꼴의 크기 

*font-style: 이탈릭체 등 스타일 속성 

*font-weight: 글꼴 굵기;   bold(굵게), normal(보통), lighter(얇게), 또는 직접 굵기를 숫자로 지정 

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" />
    <title>font-family 사용예제</title>
    <style>
        div {
            width:800px;
            margin:0 auto;
            padding:20px;
        }
 
        div:nth-child(1) {       
            font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        }
 
        div:nth-child(2) {
            font-family:MingLiU_HKSCS-ExtB;
        }
 
        div:nth-child(3) {
            font-family:'MingLiU_HKSCS-ExtB';
            font-size:32px;
        }
 
        div:nth-child(4) {
            font-family:'Bernard MT';
            font-size:1.0em;
        }
    </style>
</head>
<body>
    <div>
        abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
    </div>
 
    <div>
        abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
    </div>
 
    <div>
        abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
    </div>
 
    <div>
        abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
    </div>
</body>
</html>
 

line-height

-텍스트 가운데 세로 정렬 

-박스의 세로 길이와 동일하게 line-height 지정해야 함 

글자에 대한 정렬과 간단한 글꼴모양의 속성 

- text-align: 글자를 어느 위치에 정렬할지 (left, center, right) 

- text-decoration

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>text-align, text-decoration 사용예제</title>
    <style>
       div {
           width:800px;
           margin:0 auto;
           overflow:hidden;
           border:1px solid #cccccc;
           padding:10px;
           box-sizing:border-box;
       }
 
       div p:nth-child(1) {
           font-size:2.0em;
           text-align : center;
           height:100px;
           line-height:100px;
           text-decoration:underline;
       }
 
       div p:nth-child(2) {
           font-size:1.2em;
           text-align : left;
       }
 
       div p:nth-child(4) {
           font-size:1.2em;
           text-align : right;
       }
 
       div p:nth-child(6) {
           height:50px;
           line-height:50px;
           font-size:1.5em;
           text-align : center;
       }
 
       div p:nth-child(6) a {
           text-decoration:none;
       }
 
    </style>
</head>
<body>
    <div>
        <p>HTML5, CSS3 Document</p>
        <p>To. all member</p>
        <p>재미있게 HTML5과 CSS3를 배워봅시다!!아자아자아자아</p>
        <p>From. 누구누구</p>
        <hr />
        <p><a href="http://naver.com target="_blank">네이버로 이동</a></p>
    </div>
</body>
</html>

position

- 태그요소의 위치를 설정해주는 요소 

 

1) position: absolute  : 자신을 직접 감싸고 있는 상하,좌우를 기준으로 두는 절대적 위치.

- 주로 사용자는 top, left 속성을 함께 넣어 위치를 지정함 

- 브라우저 움직이면 같이 움직임 

2) position: fixed  : 브라우저의 스크롤바에 영향을 안받고, 화면상 그 위치 그대로 움직이지 않고 고정됨

3) position: static  : position에 아무런 속성이 없다면 default로 갖는 속성임 (있으나 없으나 같음) 

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> absollute, fixed 사용예시 </title>
    <style>
        div {
            width:100px; height:100px;
            opacity:0.7;
        }
 
       div:nth-child(1) {
           background-color:#ff0000;
           position:fixed;  /* fixed 라서 브라우저에서 스크롤바 내려도 위치 그대로 고정 */
           top:0;
           left:0;
       }
 
       div:nth-child(2) {
           background-color:#00ff00;
           position:absolute;  /* absolute 라서 브라우저에서 스크롤바 내리면 함께 움직임 */
           top:50px;
           left:50px;
       }
 
       div:nth-child(3) {
           background-color:#0000ff;
           position:absolute;
           top:100px;
           left:100px;
       }
 
       #wrap {
           width:300px; height:300px;
           position:fixed;
           top:300px; left:300px;
           background-color:yellow;
           opacity:1.0;
       }
 
       #wrap .content {
           width:100px; height:100px;
           position:absolute;
           top:100px; left:100px;
           background-color:red;
           opacity:1.0;
       }
    </style>
</head>
<body>
    <div></div>
    <div></div>
    <div></div>
 
    <div id="wrap">
        <div class="content"></div>
    </div>
</body>
</html>

아래는 position: relative를 사용한 예시입니다

(z-index는 우선순위를 부여하는 것) 

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 lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
 
    <style>
        #contain {
            width:800px;
            margin:0 auto;
            border:1px solid #cccccc;
        }
 
        #header {
            height:50px;
            background-color:#cccccc;
        }
 
        #wrap {
            height:200px;
            position:relative;
        }
        #content1 {
            width:100px; height:100px;
            background-color:red;
            border:2px dashed green;
            position:absolute;  /* 얘를 감싸는 바깥요소인 wrap의 position이 relative면, 안쪽요소들은 absolute */
            top:10px; left:10px;  /* 얘를 감싸는 wrap의 position이 relative라서 wrap 안에서 위 10px, 왼쪽 10px에 위치함 */
            z-index:20;  /*z-index 20은 10보다 크므로 더 위에 올라감*/
        }
        
        #content2 {
            width:100px; height:100px;
            background-color:yellow;
            border:2px dashed green;
            position:absolute;
            top:50px; left:50px;
            z-index:10;
        }
 
        #footer {
            height:50px;
            background-color:#cccccc;
        }
    </style>
 
</head>
<body>
    <div id="contain">
        <div id="header">HEADER</div>
        <div id="wrap">
            <div id="content1">content1</div>
            <div id="content2">content2</div>
        </div>
        <div id="footer">FOOTER</div>
    </div>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

margin 및 padding 속성

-margin: 원래의 height, width 이상으로 바깥으로 더 커짐 

-padding: 이 속성을 주게 되면, 내용(contnents)은 원래의 height, width에 맞춰 들어가지만, 내용의 background는 padding 준 정도만큼 커져있음 

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" />
    <title></title>
    <style>
        body {
            margin:0;
        }
        div {
            width:200px; height:200px;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        #content1 {
            background-color:red;
        }
 
        #content2 {
            background-color:green;
            margin:10px 10px 10px 10px; /* 내용물 밖으로 10px씩 늘어나서 공간을 차지 */
        }
 
        #content3 {
            background-color:blue;
            padding:10px 10px 10px 10px; /* 깔려있는 background가 10px씩 넓어짐 */
        }
 
         #content4 {
            background-color:orange;
            margin:10px 10px 10px 10px;
            padding:10px 10px 10px 10px;
        }
    </style>
</head>
<body>
    <div id="content1"> 200*200 </div>
    <div id="content2"> 200*200 <br /> margin </div>
    <div id="content3"> 200*200 <br /> padding </div>
    <div id="content4"> 200*200 <br /> margin <br /> padding</div>
</body>
</html>
cs

box-sizing 속성

- box-sizing을 이용하면 전체 사이즈의 크기를 지정

1) box-sizing: border-box;  : 박스를 밖으로 나가지 않도록 사이즈 형성됨  (박스를 inside로)

2) box-izing: content-box;  : 박스가 밖으로 밀려나가서 사이즈 형성됨 (박스를 outside로)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        body {
            margin:0;
            background-color:#dddddd;
        }

        div {
            width:100px;
            height:100px;
            margin:10px;
            padding:10px;
            border:10px solid #ff8d00;
        }

        div:nth-child(1) {
            margin:0;
            border:0;
            padding:0;
            background-color:#ff0000;
        }

        div:nth-child(2) {       
            background-color:#00ff00;
            box-sizing:border-box;
            
        }

        div:nth-child(3) {     
            background-color:#0000ff;
            box-sizing:content-box;
        }
    </style>
</head>
<body>
    <div>100*100</div>
    <div>100*100</div>
    <div>100*100</div>
</body>
</html>

border 속성

-박스의 두께를 주는 것 

/*
border-width:10px;      
border-style:dashed;   
border-color:#00ff21;  
이렇게 세개로 나눠서 쓰면 코드량이 많아지고 번잡해지므로 아래와 같이 한 번에 씀 
*/
border: 10px dashed #00ff21; 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        div:nth-child(1) {
            width:150px;
            height:150px;
            text-align:center;
            border-width:5px;
            border-style:solid;
            border-color:#ff6a00;
            background-color:#000000;
            color:#ffffff;
            font-weight:bold;
        }

        div:nth-child(2) {
            width:150px;
            height:150px;
            text-align:center;
            border-width:10px;
            border-style:dashed;
            border-color:#00ff21;
            background-color:#000000;
            color:#ffffff;
            font-weight:bold;
        }

        div:nth-child(3) {
            width:150px;
            height:150px;
            text-align:center;
            border:15px solid #c20b75;
            border-radius:10px 10px 0 0;
            background-color:#000000;
            color:#ffffff;
            font-weight:bold;
        }
    </style>
</head>
<body>
    <div>테스트</div>
    <div>테스트</div>
    <div>테스트</div>
</body>
</html>

url() 속성

-Background-img속성의 속성값으로 많이 사용됨. 

 

1
background-image:url('http://www.test.jpg');

 

display 속성

-화면에 어떻게 보이는지를 설정하는 속성 

-다양한 속성값이 있지만 display 속성으로 주로 몇 가지만 많이 사용됨

 

1) display: block  : 위아래 정렬  (블록을 쌓는 것처럼 개행이 저절로 되어 아래로 붙는 요소)

    (ex. <div>, <p>, <li> ) 

2) display: inline : 옆정렬 (옆으로 붙여짐); 높이는 최소값 

   (ex. <span>, <img> )

3) display: inline-block : inline 처럼 옆정렬도 되지만, block이 가지는 높이 속성도 함께 가짐 

4) display: none : 화면에서 보이지 않게 함(공간차지도 없음)

    (visibility: hidden : 화면에서는 안보이지만 공간은 그대로 차지) 

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        body div:nth-child(1) {
            width:100px;
            height:100px;
            background-color:#ff0000;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        body div:nth-child(2) {
            width:100px;
            height:100px;
            background-color:#00ff00;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        body div:nth-child(3) {
            width:100px;
            height:100px;
            background-color:#0000ff;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        body div:nth-child(4) {
            width:100px;
            height:100px;
            background-color:#ff0000;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
        }
 
        body div:nth-child(5) {
            width:100px;
            height:100px;
            background-color:#00ff00;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:inline;  /* block 요소인 div태그를 inline 요소로 바꿈 */
            margin:10px 10px 10px 10px;
        }
 
        body div:nth-child(6) {
            width:100px;
            height:100px;
            background-color:#0000ff;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:inline;  /* block 요소인 div태그를 inline 요소로 바꿈 */
        }
        body div:nth-child(7) {
            width:100px;
            height:100px;
            background-color:#ff0000;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:none;  /* none: 화면에서 날려보내기 (공간마저도 없앰) */
        }
        body div:nth-child(8) {
            width:100px;
            height:100px;
            background-color:#00ff00;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:inline;    /* block 요소인 div태그를 inline 요소로 바꿈 */
        }
        body div:nth-child(9) {
            width:100px;
            height:100px;
            background-color:#0000ff;
            color:#ffffff;
            font-weight:bold;
            text-align:center;
            display:inline-block; /*inline-block으로 하면 옆정렬이 되면서 & block요소로써 갖는 100px의 height 속성 */
        }
    </style>
</head>
<body>
 
    <div>
        content1
    </div>
    <div>
        content2
    </div>
    <div>
        content3
    </div>
 
    <div>
        content4
    </div>
    <div>
        content5
    </div>
    <div>
        content6
    </div>
    <div>
        content7
    </div>
    <div>
        content8
    </div>
    <div>
        content9
    </div>
 
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

opacity 속성

-투명도를 나타냄

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
<style>
        ul li {
            display:inline-block;  /*옆정렬시킴. 이 속성이 없다면 위아래 정렬 되었을것*/
            width:200px; height:100px;
            text-align:center;
            background-color:#dddddd;
        }
 
        ul li:nth-child(2) {
            background-color:#dddddd;
            opacity:0.7;
        }
 
        ul li:nth-child(3) {
            background-color:#dddddd;
            opacity:0.4;  /* 낮을수록 투명도 높아짐 */
        }
    </style>
</head>
<body> 
    <ul>
        <li>우리나라 만세!!</li>
        <li>대한민국 만세!!</li>
        <li>KOREA FIGHTING!!</li>
    </ul>
</body>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

선택자란, 특정 택를 선택하여 해당 태그의 속성을 변경하는 목적 (css의 목적이기도 함)

 

태그선택자

- 속성 변경하고자 하는 태그를 선택 가능 

ex) p { } 

ex) li { } 

ex) div { } 

전체선택자(*)

* {

     /*여기에 css 속성 넣으면 해당 스타일시트에 모두 적용 됨 */

}

 

 id(#)와 class(.)선택자

-id: 스타일을 지정할 때 한 가지만 지정해서 쓰는 이름 (표기방식은 #이름)

-class: 그룹으로 묶어서 스타일을 지정할 때 쓰는 이름  (표기방식은 .이름)

 

태그, id, class 혼합선택자

- ul li.menu {}   : ul 태그 중, li 태그 안에 menu라는 클래스 가진 태그만 선택 

 

 

속성선택자

-tag의 속성을 선택하여 css의 속성을 설정할 수 있음 

 

 

후손 및 자손선택자

*자손선택자: 내 바로 밑에 태그들만 선택

  ex) div > li { }     <-- div안 바로 다음에 위치한 li태그들만 선택

 

*후손선택자: 내 밑 모든 태그들 선택   

  ex) div li { }       <- div안에 있는 li태그들 모~두 선택(li의 위치가 얼마나 안에 있던지 상관x) 

 

 

 

동위선택자

-태그의 동등한 위치를 판단하여 css속성을 설정 
ex) h3~div : h3과 동등한 위치에 있는 div를 전부다 선택 (h3 나 자신은 제외) 
ex) h3+div : h3과 동등한 위치에 있는 div중에 내 바로 밑에 태그 하나만 선택 (h3 나 자신은 제외) 

 

 

반응선택자

-마우스의 반응에 따른 속성을 설정 (hover) 

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <style>
        ul > li {
            font-size: 20px;
            font-weight: bold;
            color: coral;
        }
 
        li:hover {
            color:blue;
        }
    </style>
</head>
<body>
    <div>
        <ul>
            <li>menu1</li>
            <li>menu2</li>
            <li>menu3</li>
            <li>menu4</li>
            <li>menu5</li>
        </ul>
    </div>
</body>
</html>
 

↑마우스를 올리는 곳에 폰트색상이 블루로 변함

상태 선택자

-상태 선택자란 상태에 따라 css속성이 변하는 설정을 할 수 있음 

 

-focus: 마우스로 해당 form태그의 input에 눌렀을 때 해당하는 곳 

-enabled: disabled로 지정하지 않은 곳 

-disabled: 서버에서 값을 미리 설정하여 변경 못하도록 

 

 

구조선택자  

-구조에 따라서 css속성이 변하는 설정을 할 수 있음

ex) ul li:nth-child(1) <-- 첫번째 자식만 선택

ex) ul li:nth-chuld(2) <-- 두번째 자식만 선택 

ex) ul li:nth-child(2n)     <-- 짝수만 선택

ex) ul li:nth-child(0n+1)     <-- 홀수만 선택

 

 

문자선택자 

-특정 문자 또는 문자열을 선택하여 css속성을 설정 할 수 있음 

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
<!DOCTYPE html>
 
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
 
        #wrap {
            width:800px;
            margin:0 auto;
        }
 
        #header {
            border-bottom:1px solid #cccccc;
        }
 
        #content p:first-child::selection {  /* p태그들 중 첫번째 자식의 경우, 마우스로 드래그하여 선택한 부분만 속성 지정 */
            background-color:blue;
            color:yellow;
        }
 
        #history2::first-letter, #history1::first-letter{ /* #history2와 histroy1의 첫번째 글자 */
            font-size:2em;
        }
        
        #history2::first-line, #history1::first-line{ /* #history2와 histroy1의 첫번째 줄 */
            font-weight:bold;
            color:#2160d1;
        }
 
    </style>
</head>
<body>
    <div id="wrap">
 
        <div id="header">
            <h1>설립개요</h1>
        </div>
 
        <div id="content">
            <p>
                중소기업 지원업무의 전문성과 효율성을 확보하고 중소기업에 대한 기술, 경영, 인력 등의 종합지원체계를 구축함으로.....
            </p>
            <p id="history2">
                2014 04월 09일<br />서울산업진흥원 사명변경06월 30일 서울산업진흥원 상암DMC 이전
            </p>
            <p id="history1">
                2013 01월 12일<br />다누리 시민청 개관05월 09일 꿈꾸는청년가게 명동점 개관05월 10일 큐비드 광화문 개관06월 21일 다누리 강남점 개관07월 20일 서울크리에티브랩 개관08월 27일 다누리 성북점 개관
            </p>
        </div>
 
    </div>
 
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

아래는 브라우저 화면

링크선택자

문서에서 링크(href)되어 있는 문자를 선택하여 css 속성을 설정 할 수 있음 

- a태그가 걸려있는 것들 찾아서 뒤에 어떤 속성을 지정하고 싶을 때 사용 

 

 

 

 

부정선택자

나를 제외한 모든 태그에 css 속성을 적용할 수 있음 

+ Recent posts