κ°μ μ νμ
νΉμ μνμ μλ μμλ νΉμ μμμ μΌλΆλΆμ μ ν
κ°μ μ νμλ μν, ꡬ쑰, λμμ λ°λΌ μ¬λ¬ κ°μ§λ‘ λΆλ₯λ©λλ€.
λμ κΈ°λ° κ°μ μ νμ
μ νμ μ’
λ₯ | λ΄μ© |
:hover | λ§μ°μ€ 컀μκ° μμ μμ μ¬λΌκ° μλ μνλ₯Ό μ ν |
:active | λ§μ°μ€ ν΄λ¦ μκ°λΆν° λκΈ° μ§μ κΉμ§ μνλ₯Ό μ ν |
:focus | μ
λ ₯ νΌμμ ν€λ³΄λ μ
λ ₯μ κΈ°λ€λ¦¬λ μνλ₯Ό μ ν |
:link | μμ§ ν΄λ¦νμ§ μμ λ§ν¬ μνλ₯Ό μ ν |
:visited | λ°©λ¬Έν νμ λ§ν¬ μνλ₯Ό μ ν |
:target | λ΄λΆ λ§ν¬λ‘ νΉμ λΆλΆμΌλ‘ μ΄λν λ μ¬μ© |
:checked | 체ν¬λ μν(checkbox λλ radio λ²νΌ) μμλ₯Ό μ ν |
ꡬ쑰 κΈ°λ° κ°μ μ νμ
μ νμ μ’
λ₯ | λ΄μ© |
:first-child | 첫 λ²μ§Έ μμμ μ ν |
:last-child | λ§μ§λ§ μμμ μ ν |
:nth-child(n) | nλ²μ§Έ μμμ μ ν |
:nth-last-child(n) | λ§μ§λ§μμλΆν° nλ²μ§Έ μμμ μ ν |
:only-child | μμ μμκ° νλλ§ μλ μμλ₯Ό μ ν |
:first-of-type | μ νμ μ€ μ²« λ²μ§Έλ‘ λμ€λ μμλ₯Ό μ ν |
:last-of-type | μ νμ μ€ λ§μ§λ§μΌλ‘ λμ€λ μμλ₯Ό μ ν |
:nth-of-type(n) | νΉμ νκ·Έμ nλ²μ§Έ μμμ μ ν |
:nth-last-of-type(n) | λ§μ§λ§μμλΆν° nλ²μ§Έλ‘ μ νλλ νΉμ νκ·Έμ μμλ₯Ό μ ν |
:only-of-type | ν΄λΉ νκ·Έ νμ
μ μ μΌν μμλ₯Ό μ ν |
:empty | μμ μμκ° μλ μμλ₯Ό μ ν |
μν κΈ°λ° κ°μ μ νμ
μ νμ μ’
λ₯ | λ΄μ© |
:enabled | νμ±νλ νΌ μμλ₯Ό μ ν |
:disabled | λΉνμ±νλ νΌ μμλ₯Ό μ ν |
:not(x) | x μ νμλ₯Ό μ μΈν λλ¨Έμ§ μμλ₯Ό μ ν |
κΈ°ν κ°μ μ νμ
μ νμ μ’
λ₯ | λ΄μ© |
:root | μΉ νμ΄μ§μ μ΅μμ μμ (html)λ₯Ό μ ν |
:first-line | μμμ 첫 λ²μ§Έ μ€μ μ ν |
:first-letter | μμμ 첫 λ²μ§Έ κΈμλ₯Ό μ ν |
:before | μμμ μμ λΆλΆμ μ½ν
μΈ λ₯Ό μ½μ
|
:after | μμμ λ λΆλΆμ μ½ν
μΈ λ₯Ό μ½μ
|
:lang | νΉμ μΈμ΄ μμ±μ κΈ°μ€μΌλ‘ μ ν |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>κ°μ μ νμ</title>
<style>
a:link {
color: blue;
text-decoration: none;
}
a:visited {
color: coral;
}
a:hover {
color: red;
text-decoration: underline;
}
a:active {
color: royalblue;
}
a:focus {
color: black;
}
input:focus {
border: 2px solid #007bff;
background-color: #e6f7ff;
outline: none;
}
p::first-line {
font-weight: bold;
color: darkblue;
}
p::first-letter {
font-size: 2em;
color: #ff4500;
}
.box::before {
content: 'β ';
color: green;
font-size: 1.2em;
}
.box::after {
content: ' βΆ';
color: green;
font-size: 1.2em;
}
p:lang(en) { font-style: italic; }
p:lang(ko) { font-style: bold; font-size: 20px; }
</style>
</head>
<body>
<h1>κ°μ μ νμ</h1>
<a href="http://www.test.com">λ§ν¬ νκ·Έμ
λλ€</a>
<br>
<a href="">λ§ν¬ νκ·Έμ
λλ€</a>
<br><br>
<label for="name">μ΄λ¦</label>
<input type="text" name="name" placeholder="μ΄λ¦μ μ
λ ₯νμΈμ">
<br><br>
<p>
첫κΈμ 첫 λ²μ§Έ λ¬Έμ₯ <br>
λ λ²μ§Έ λ¬Έμ₯
μΈ λ²μ§Έ λ¬Έμ₯
</p>
<div class="box">
:before
컨ν
μΈ
:after
</div>
<p lang="en">English</p>
<p lang="ko">Korean</p>
</body>
</html>
HTML
볡μ¬
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>κ°μμ νμ - μμμ ν</title>
<style>
table {
border: 1px solid black;
border-collapse: collapse; /* ν
μ΄λΈ, μ
ν
λ리λ₯΄ ν©μΉ¨ */
}
th, td {
border-bottom: 1px solid black;
}
table.first {
width: 100%;
border-radius: 8px;
overflow: hidden;
box-shadow: 5px 5px 5px #aaa;
/* κ·Έλ¦Όμ : xμΆ yμΆ λΈλ¬ μμ */
}
table.first th {
padding: 8px;
background-color: cornflowerblue;
color: white;
letter-spacing: 3px;
}
/* th νκ·Έ μ€ 2λ²μ§Έ μμλ₯Ό μ ν */
table.first th:nth-child(2)::first-letter {
letter-spacing: 45px;
text-align: center;
}
table.first td {
padding: 10px;
text-align: center;
}
/* odd - μμ μμ μ€ νμμΈ μμλ§ μ ν */
table.first tr:nth-child(odd) {
background-color: lightgray;
}
/* even - μμ μμ μ€ μ§μμΈ μμλ§ μ ν */
table.first tr:nth-child(even) {
background-color: azure;
}
table.first td:first-child { width: 10%; }
table.first td:nth-child(2) { width: 70%; }
table.first td:last-child { width: 25%; }
table.first tr:hover {
background-color: royalblue;
color: white;
cursor: pointer;
}
/* ----------------------------------------- */
/* :empty - λ΄μ©μ΄ μλ μν */
p:empty { margin: 100px; }
table.second {
width: 100%;
border-collapse: collapse;
}
table.second th {
padding: 8px;
background-color: orange;
color: white;
text-align: center;
}
table.second td {
padding: 10px;
text-align: center;
}
/* 첫λ²μ§Έ, 2λ²μ§Έ, λ§μ§λ§ μμ μ ν */
table.second td:first-of-type { width: 15%; }
table.second td:nth-of-type(2) { width: 65%; }
table.second td:last-of-type { width: 20%; }
/* nth-of-child */
/* : μμμμ μ 체λ₯Ό κΈ°μ€μΌλ‘ μμλ₯Ό μ§μ νλ€ */
section.part1 *:first-child { background-color: cornflowerblue; }
section.part1 *:last-child { background-color: coral; }
section.part1 div:nth-child(2) { background-color: lightseagreen; }
section.part1 div:nth-last-child(2) { background-color: mediumpurple; }
/* nth-of-type */
/* : μ§μ ν μμλ€λΌλ¦¬λ§ μμλ₯Ό μ§μ νλ€ */
section.part2 div:first-of-type { background-color: cornflowerblue; }
section.part2 div:last-of-type { background-color: coral; }
section.part2 div:nth-of-type(2) { background-color: lightseagreen; }
section.part2 div:nth-last-of-type(2) { background-color: mediumpurple; }
</style>
</head>
<body>
<h1>κ°μ μ νμ</h1>
<h3>nth-of-child</h3>
<table class="first">
<tr>
<th>λ²νΈ</th>
<th>μ λͺ©</th>
<th>λ μ§</th>
</tr>
<tr>
<td>1</td>
<td>κ°μμ νμ</td>
<td>2024.09.13</td>
</tr>
<tr>
<td>2</td>
<td>νμμ νμ</td>
<td>2024.08.05</td>
</tr>
<tr>
<td>3</td>
<td>μΈμ μ νμ</td>
<td>2024.10.07</td>
</tr>
</table>
<div class="space"></div>
<hr>
<p></p>
<h3>nth-of-type</h3>
<table class="second">
<tr>
<th>λ²νΈ</th>
<th>μ λͺ©</th>
<th>λ μ§</th>
</tr>
<tr>
<td>1</td>
<td>κ°μμ νμ</td>
<td>2024.09.13</td>
</tr>
<tr>
<td>2</td>
<td>νμμ νμ</td>
<td>2024.08.05</td>
</tr>
<tr>
<td>3</td>
<td>μΈμ μ νμ</td>
<td>2024.10.07</td>
</tr>
</table>
<p></p>
<hr>
<h3>nth-child vs nth-of-type</h3>
<section class="part1">
<h2>κ°μμ νμ ννΈ1 - nth-child</h2>
<div>div μμ 1</div>
<div>div μμ 2</div>
<div>div μμ 3</div>
<div>div μμ 4</div>
<div>div μμ 5</div>
<p>p μμ 1</p>
</section>
<p></p>
<section class="part2">
<h2>κ°μμ νμ ννΈ2 - nth-of-type</h2>
<div>div μμ 1</div>
<div>div μμ 2</div>
<div>div μμ 3</div>
<div>div μμ 4</div>
<div>div μμ 5</div>
<p>p μμ 1</p>
</section>
<div style="height: 400px;"></div>
</body>
</html>
HTML
볡μ¬