Search

가상 μ„ νƒμž

가상 μ„ νƒμž

νŠΉμ • μƒνƒœμ— μžˆλŠ” μš”μ†Œλ‚˜ νŠΉμ • μš”μ†Œμ˜ 일뢀뢄을 선택
가상 μ„ νƒμžλŠ” μƒνƒœ, ꡬ쑰, λ™μž‘μ— 따라 μ—¬λŸ¬ κ°€μ§€λ‘œ λΆ„λ₯˜λ©λ‹ˆλ‹€.

λ™μž‘ 기반 가상 μ„ νƒμž

μ„ νƒμž μ’…λ₯˜
λ‚΄μš©
: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
볡사