η‘μ
Pseudo-elements (μμ¬ μμ) λ³Έλ¬Έ
π’ Pseudo-elements
HTML λ¬Έμμλ μ€μ λ‘ μ‘΄μ¬νμ§ μλ κ°μμ μμλ₯Ό CSSλ‘ μμ±νμ¬ μ€νμΌμ μ μ©νλ μμ.
1οΈβ£ λ΄μ© μλ€μ μ½ν μΈ λ₯Ό μΆκ°νλ κ°μ μμ
/* λ§ν¬ μμ νμ΄ν μμ΄μ½ λ£κΈ° */
a::before {
content: "β ";
color: blue;
}
/* νμ μ
λ ₯ νλͺ© λ€μ λΉ¨κ° λ³ν λ£κΈ° */
.required::after {
content: "*";
color: red;
}
- ::before: μ νν μμμ λ΄λΆ μμ κ°μ μμ μΆκ°.
- ::after: μ νν μμμ λ΄λΆ λ€μ κ°μ μμ μΆκ°.
- νΉμ§: λ°λμ content μμ±μ μΆκ°ν΄ λ΄μ©μ μ λ ₯. ( π μ΄λͺ¨ν°μ½ μ½μ λ¨μΆν€ (win + .))
- μ©λ: μμ΄μ½ μΆκ°, κΎΈλ° μμ(μ₯μμ ), λ¨μ νμ(μ: 'μ', '%') λ±μ HTML μμ μμ΄ λ£μ λ μ¬μ©.
2οΈβ£ κΈμ λ° μμ μ ν κ°μ μμ
/* λ¬Έλ¨μ 첫 κΈμλ₯Ό ν¬κ² λ§λ€κ³ λΉ¨κ°μμΌλ‘ λ³κ²½ */
p::first-letter {
font-size: 3em;
color: red;
float: left;
margin-right: 5px;
}
/* λλκ·Ένμ λ λ°°κ²½μκ³Ό κΈμμ λ³κ²½ */
::selection {
background-color: black;
color: yellow;
}
- ::first-line: μμμ 첫 λ²μ§Έ μ€ μ μ©.
- ::first-letter: μμμ 첫 λ²μ§Έ κΈμ μ μ©. (μ λ¬Έμ΄λ μ‘μ§μ 첫 κΈμ κ°μ‘° ν¨κ³Ό)
- ::selection: μ¬μ©μκ° λ§μ°μ€λ‘ λλκ·Έ(μ ν)λ μμ μ μ©.
3οΈβ£ κ·Έ μΈ
input::placeholder {
color: gray;
}
- ::placeholder: input νκ·Έμ placeholder μμ± ν μ€νΈμλ§ μ€νμΌ μ μ©. (μ λ ₯ ννΈ μ€νμΌλ§)
li::marker {
color: red;
}
- ::marker: 리μ€νΈ μ μ μ€νμΌ μ μ©.
π₯ κ°μ μμ μμΉμ‘°μ position π₯
.card {
position: relative;
}
.card::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.3);
}
/* μ€λ²λ μ΄ ν¨κ³Ό λ§λ€ λ μμ£Ό μ¬μ© */
https://yo-u-loo.tistory.com/35
CSSμ Position μμ±
π’ Position μμ± μμκ° λ¬Έμ μμμ μ΄λ»κ² μμΉν μ§λ₯Ό μ μ. πΉ position μ’ λ₯μ νΉμ§ μμ±κ°μ€λͺ top/right/bottom/left μ¬μ©λ¬Έμ νλ¦ μν₯νμ© μμstaticμΌλ° λ¬Έμ νλ¦λλ‘ λ°°μΉ (κΈ°λ³Έκ°)β 무μλ¨μΌ
yo-u-loo.tistory.com
πβ POINT πβ
βοΈ κ°μ μμλ μ½λ‘ 2κ°(::)λ₯Ό μ¬μ©νμ¬ μμ±νλ€. βοΈ
βοΈ ::before μ ::after λ κΈ°λ³Έμ μΌλ‘ μΈλΌμΈ(inline) μμλ‘, ν¬κΈ°λ₯Ό μ‘°μ νλ €λ©΄ display: blockμ΄λ inline-blockμΌλ‘ λ°κΏμΌ νλ€. βοΈ
βοΈ HTML μ½λλ₯Ό κΉ¨λνκ² μ μ§νλ©΄μ λμμΈμ μΈ μμλ₯Ό λ£κ³ μΆμ λ μ¬μ©νλ©΄ μ’λ€. βοΈ
π κ°μ μμ vs κ°μ ν΄λμ€ νλμ λΉκ΅ π
| κ΅¬λΆ | κ°μ ν΄λμ€ (Pseudo-class) | κ°μ μμ (Pseudo-element) |
| κΈ°νΈ | μ½λ‘ 1κ° (:) | μ½λ‘ 2κ° (::) |
| μλ―Έ | νΉμ μνλ₯Ό μ ν | νΉμ λΆλΆμ μ ννκ±°λ μμ± |
| μμ | :hover, :nth-child | ::before, ::after, ::selection |
| νΉμ§ | μ€μ λ‘ μ‘΄μ¬νλ μμμ μν λ³κ²½ | μ‘΄μ¬νμ§ μλ μμλ₯Ό λ§λ€κ±°λ λΆλΆ μμ |
βοΈ μ€μ μμ μ½λ: λ©λ΄ ꡬλΆμ λ§λ€κΈ° βοΈ
<style>
.menu-list { list-style: none; display: flex; }
.menu-list li { margin-right: 10px; position: relative; }
/* λ§μ§λ§ νλͺ©μ μ μΈν λͺ¨λ 리μ€νΈ λ€μ μΈλ‘μ μΆκ° */
.menu-list li:not(:last-child)::after {
content: "|";
margin-left: 10px;
color: #ccc;
}
/* νΈλ² μ λ°μ€ μ λλ©μ΄μ
μ© κ°μ μμ */
.menu-list li:hover::before {
content: "";
position: absolute;
bottom: -5px;
width: 100%;
height: 2px;
background-color: orange;
}
</style>
<ul class="menu-list">
<li>ν</li>
<li>μκ°</li>
<li>μλΉμ€</li>
<li>λ¬Έμ</li>
</ul>
'<style>' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
| Functionsμ filterμμ±κ³Ό ν¨μ (0) | 2026.03.27 |
|---|---|
| transform μμ±κ³Ό functions (ν¨μ) (0) | 2026.03.26 |
| Pseudo-class (μμ¬ ν΄λμ€) (0) | 2026.03.26 |
| Attribute Selectors (0) | 2026.03.25 |
| Combination Selector (0) | 2026.03.25 |