
<style type="text/css"></style>안에서 사용하는 것이 일반적임선택자 { 속성 : 값; }
- 각 속성의 설정은 ';' 으로 구분
*{color : 색상;} : 페이지 전체 태그에 색상 적용
p {color: 색상;} : p태그에 색상 적용
h3, h4, h5, sspan { color: 색상;} : 태그에 색상 적용
<style type="text/css">
#select_1{color: red;}
#select_2{color: blue;}
.title{color: brown;}
h4.title{color: orange;}
.type{color: gray;
font-weight:30px}
</style>
<body>
<p id = "select_1">#으로 시작해서 웹페이지에서 CSS로 꾸미고자 하는 id 선택</p>
<p id = "select_2">#으로 시작해서 웹페이지에서 CSS로 꾸미고자 하는 id 선택</p>
<h3 class="title">내용</h3>
<h4 class="title">내용</h4>
</body>
<style type="text/css">
#header h2 {color: blue;}
#section h2 {color: red;}
#content p {color: gray;}
</style>
<body>
<h2>하위 선택자</h2>
<div id = "header">
<h2>header</h2>
<div id = "nav">
<h3>navigation</h3>
</div>
</div>
<br/>
<div id = "section">
<h2>section</h2>
<p>section area</p>
</div>
<br/>
<div id = "heading">
<h2>heading</h2>
<div id = "content">
<p>문단A</p>
<p>문단B</p>
<p>문단C</p>
</div>
</div>
</body>
<style type="text/css">
#content > p {color: gold;}
</style>
----------------------------------------------
<body>
<div id ="content">
<p>문단 A</p>
<p>문단 B</p>
<div>
<p>문단 C</p>
</div>
</div>
<p>문단 D</p>
</body>
실행 결과값

<style type="text/css">
input type{color: gray;}
input[type=password] {background-color: yellow;}
</style>
-------------------------------------------------------
<body>
<h1>기본 속성 선택자</h1>
<br/>
<form action="#">
<p>text : <input type="text" id="data" name="data"/></p>
<p>password : <input type="password" id="pwd" name="pwd"/></p>
</form>
</body>
- 인접 형제 선택자
선택자_A + 선택자_B
: 선택자_A 의 요소 바로 뒤에 위치하는 선택자_B 요소를 선택
- 일반 형제 선택자
선택자_A ~ 선택자_B
: 선택자_A 의 형제 요소중에서 선택자_A 뒤에 위치하는 선택자_B 요소를 모두 선택
<style type="text/css">
h2 + h3 { color: red;}
h2 ~ h3 { background-color: orange;}
</style>
-----------------------------------------------------
<body>
<!-- 인접 형제 선택자 -->
<h1>인접 선택자</h1>
<h3>제목 - 3</h3>
<h2>제목 - 2</h2>
<!-- 일반 형제 선택자 -->
<h3>제목 - 3</h3>
<h3>제목 - 3</h3>
<h3>제목 - 3</h3>
<div id="content">
<h3>content - h3</h3>
</div>
<h3>제목 - 3</h3>
</body>
:link -> 선택자가 방문하지 않은 링크 (a태그에만 적용됨):visited -> 선택자가 방문한 링크:hover -> 선택자가 마우스가 올라갔을 때:active -> 선택자가 클릭된 상태일때<style type="text/css">
a:link{ color: orange;}
a:visited{color: green;}
a:hover{color: red;
background-color: yellow;}
#test-1 a:active {color : blue;}
</style>
----------------------------------------------------
<body>
<h1>반응선택자</h1>
<h2 id = "test-1"><a href="https://www.naver.com" target ="_blank">NAVER</a></h2>
<h2 id = "test-1"><a href="https://www.daum.net" target ="_blank">DAUM</a></h2>
</body>
:first-child -> 형제 관계 중에서 첫번째 요소를 선택:last-child -> 형제 관계 중에서 마지막 요소를 선택:nth-child(n) -> 형제 관계 중에서 앞에서 n번째 요소를 선택:nth-last-child(n) -> 형제 관계 중에서 뒤에서 n번째 요소를 선택:first-of-type -> 형제 관계 중에서 첫번째로 나오는 태그를 선택:last-of-type -> 형제 관계 중에서 마지막으로 나오는 태그를 선택:nth-of-type(n) -> 형제 관계 중에서 앞에서 n번째로 나오는 태그를 선택:nth-last-of-type(n) -> 형제 관계 중에서 뒤에서 n번째로 나오는 태그를 선택<link rel="stylesheet" type="text/css" href="external-style.css"/>
/*external-style.css*/
@charset "UTF-8";
#external > p{
font-size: 30px;
color: pink;
}