λͺ©μ°¨
μ΄λ²μλ μμλ₯Ό λΆμ¬νλ κ°μν΄λμ€λ₯Ό μμ보μλ€.
nth-child
nth-childλ μμλ₯Ό λΆμ¬νλ κ°μν΄λμ€μ΄λ€.
(κ°μ₯ λνμ μΈ μμλΆμ¬ κ°μν΄λμ€)
μ¬μ©λ²
μ νμ:nth-child(μμ)
(λμ΄μ°κΈ°λ μμ X)
μμ
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
.box {
border: 5px solid #000;
width: 1000px;
text-align: center;
}
.box div {
border: 5px solid #000;
margin: 10px;
width: 200px;
height: 200px;
display: inline-block;
}
μμ κ°μ΄ λΆλͺ¨μμμΈ 'box'ν΄λμ€μ 4κ°μ μμμμκ° μλ€.
μ΄ 4κ°μ μμμ μμλ₯Ό λΆμ¬ν΄λ³΄λ©΄
.box div:nth-child(1) {
background-color: dodgerblue;
}
.box div:nth-child(2) {
background-color: red;
}
.box div:nth-child(3) {
background-color: blueviolet;
}
.box div:nth-child(4) {
background-color: gold;
}
μΌμͺ½λΆν° 1, 2, 3, 4λ²μ§Έλ‘ μμκ° λΆμ¬κ° λμλ€!
νμ§λ§ μ£Όμν μ μ΄ μλ€.
<div class="box">
<p>hello</p>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
CSSλΆλΆμ λ³κ²½νμ§ μκ³ μμμμμ pνκ·Έλ₯Ό μΆκ°νμλ€.
μμμμ μ€ divνκ·Έμ μμλ₯Ό λΆμ¬νμμ§λ§,
μλ±ν pνκ·Έλ ν¨κ» μΉ΄μ΄νΈλ₯Ό ν΄λ²λ Έλ€.
(2, 3, 4, 5λ²μΌλ‘ μμκ° λ°λ¦Ό)
μ¦, nth-childλ λ¨μ§ μΆν μμλ₯Ό λ°μ§λ€.
(νκ·Έλ₯Ό ꡬλΆνμ§ μκ³ !)
μ΄λ₯Ό ν΄κ²°νκΈ° μν λ€λ₯Έ λ°©λ²μ΄ μλ€.
nth-of-type
nth-of-typeμ νκ·Έλ₯Ό ꡬλΆνμ¬ μμλ₯Ό λΆμ¬νλ€.
.box div:nth-of-type(1) {
background-color: dodgerblue;
}
.box div:nth-of-type(2) {
background-color: red;
}
.box div:nth-of-type(3) {
background-color: blueviolet;
}
.box div:nth-of-type(4) {
background-color: gold;
}
μμ²λΌ ν΄λΉ μ νμμκ²λ§ μμκ° μ μ©μ΄ λ κ²μ μ μμλ€.
'π | WEB DEV > HTML CSS' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
CSSμ ν¬κΈ°λ¨μλ€!(px, em, rem, vw λ±) (0) | 2022.01.09 |
---|---|
CSS κ°μν΄λμ€ (3)_μμ κ°μν΄λμ€[2] (first-child, last-child) (0) | 2022.01.07 |
CSS κ°μν΄λμ€ (1)-2_λ§μ°μ€ μ€λ² ν¨κ³Ό(hover, transition) μΆκ°! (0) | 2022.01.07 |
CSS κ°μν΄λμ€ (1)_λ§μ°μ€ μ€λ² ν¨κ³Ό(hover, transition) (0) | 2022.01.07 |
CSS ν¬μ§μ (3)_μνλ μμΉμ λ± λ°°μΉνκΈ°! (0) | 2022.01.06 |
λκΈ