Front-End/CSS

μŠ€νƒ€μΌ 상속

πŸŒ³μ§€ν˜œμ˜ 숲 2022. 9. 19. 01:09

상속

<div class="ecosystem">μƒνƒœκ³„
    <div class="animal">동물
        <div class="tiger">ν˜Έλž‘μ΄</div>
        <div class="lion">μ‚¬μž</div>
        <div class="elephant">코끼리</div>
    </div>
    <div class="plant">식물</div>
</div>
.animal {
	color: red;
}

- .animal의 μžμ‹ μš”μ†ŒκΉŒμ§€ 영ν–₯을 λ―ΈμΉœλ‹€.

β€» μƒμ†λ˜λŠ” CSS 속성듀 (λŒ€λΆ€λΆ„ κΈ€μž / 문자 κ΄€λ ¨ 속성듀)
- font-style: κΈ€μž 기울기
- font-weight: κΈ€μž λ‘κ»˜
- font-size: κΈ€μž 크기
- line-height: 쀄 높이
- font-family: 폰트(μ„œμ²΄)
- color: κΈ€μž 색상
- text-align: μ •λ ¬

 

 

 

κ°•μ œ 상속

β–Ά inherit: 상속 κΈ°λŠ₯이 μ—†λŠ” μ†μ„±λ“€μ—κ²Œ 상속 κΈ°λŠ₯을 κ°•μ œλ‘œ λΆ€μ—¬ν•œλ‹€.

<div class="parent">
	<div class="child"></div>
</div>
.parent {
    width: 300px;
    height: 200px;
    background-color: red;
}

.child {
    width: 100px;
    height: inherit;
    background-color: inherit;
}

- μžμ‹ μš”μ†Œμ— inherit을 μ„€μ •ν•˜λ©΄ λΆ€λͺ¨ μš”μ†Œμ˜ 속성을 μƒμ†ν•œλ‹€.