[CSS] display μμ±
display μμ±
CSSμ displayλ μμκ° μ΄λ»κ² 보μ¬μ§ μ§λ₯Ό κ²°μ νλ μμ±μΌλ‘, ꡬ문μ λ€μκ³Ό κ°μ΅λλ€.
display: value;
valueμ μ£Όλ‘ μ°μ΄λ μμ±κ°μ block, inline, inline-block, noneμ΄ μμ΅λλ€.
block μμ
block μμμλ <p>, <h1>~<h6>, <div>, <ol>, <ul>, <li>, <form>λ±μ΄ μμ΅λλ€.
μ΄ μμλ€μ widthμ heightλ₯Ό μ§μ ν μ μκ³ , λ§μ½ μ§μ νμ§ μμμκ²½μ° μ 체 κ°λ‘ μ¬μ΄μ¦λ₯Ό κ°μ§λλ€.
λν blockμμ λ€μμ μ€λ μμλ μλ‘μ΄ lineμμ μμνκΈ° λλ¬Έμ μμλ€μ΄ μλλ‘ μμ΄κ² λ©λλ€.
<block μμ μμ>
1
2
3
4
|
<h1 style="border: 1px solid black;">Hello</h1>
<div style="width: 100px; height: 100px; background-color: red;"></div>
<div style="width: 100px; height: 100px; background-color: blue;"></div>
<div style="width: 100px; height: 100px; background-color: green;"></div>
|
cs |

<h1>μ widthλ₯Ό μ νμ§ μμκΈ° λλ¬Έμ νλ©΄ μ μ²΄κ° κ°λ‘μ¬μ΄μ¦κ° λκ³ , 3κ°μ <div>λ width: 100px; height: 100pxλ‘ μ€μ λ©λλ€. μ¬κΈ°μ μ£Όμν μ μ <div> μμ λ΄μ λ΄μ©μ μμ±νμ§ μμ μνκΈ° λλ¬Έμ, λ§μ½ widthλ heightλ₯Ό μ§μ ν΄μ£Όμ§ μλλ€λ©΄ <div>μ μ¬μ΄μ¦λ 0μ΄ λμ΄ νλ©΄μ 보μ΄μ§ μμ΅λλ€. 3κ°μ <div>κ° μμΌλ‘ μμΌ κ³΅κ°μ΄ μμμλ κ°κ° μλ‘μ΄ μ€μμ μμνκ³ μλ κ²λ λ³Ό μ μμ΅λλ€.
inline μμ
inline μμμλ <span>, <img>, <a> λ±μ΄ μμ΅λλ€.
μ΄ μμλ€μ νκ·Έλ΄μ contentμ μν΄ widthκ° μ ν΄μ§λ©°, widthλ₯Ό λ°λ‘ μ§μ ν μ μμ΅λλ€.
λν blockμμμλ λ€λ₯΄κ² μμκ° νμ μλ‘μ΄ μ€μμ μμνλ κ²μ΄ μλκΈ° λλ¬Έμ μ¬λ¬ κ°μ inline μμκ° μμ κ²½μ° μμΌλ‘ μμ΄κ² λ©λλ€.
<inline μμ μμ>
1
2
3
|
<span style="padding: 10px; background-color: red;">inline1</span>
<span style="padding: 10px; background-color: blue;">inline2</span>
<span style="padding: 10px; background-color: green;">inline3</span>
|
cs |
<span>μ inline μμκΈ° λλ¬Έμ μλ‘μ΄ μ€μμ μμνμ§ μκ³ , μμΌλ‘ μμ΄λ κ²μ νμΈν μ μμ΅λλ€.
displayμ μμ±κ°
displayμ λνμ μΈ μμ± κ°μ block, inline, inline-block, noneμ΄ μμ΅λλ€.
-
display: block;
// μμλ₯Ό block μμμ²λΌ 보μ΄κ² ν¨ -
display: inline;
// μμλ₯Ό inline μμμ²λΌ 보μ΄κ² ν¨ -
display: inline-block;
// inline μμμ²λΌ format λμ§λ§ width, heightλ μ μ© κ°λ₯νκ² ν¨ -
display: none;
// μμλ₯Ό μΉ μ¬μ΄νΈμμ μ¬λΌμ§κ² ν¨(removed)
noneμ λν μ€λͺ μ λ§λΆμ΄μλ©΄, μμκ° μ 보μ΄κ² ν λΏλ§ μλλΌ νλ©΄μμ ν΄λΉ μμμ κ³΅κ° ν λΉμ μμ νμ§ μμ΅λλ€.
λ§μ½ μμκ° κ³΅κ°μ μ°¨μ§νμ§λ§ μ 보μ΄λλ‘ νκ³ μΆλ€λ©΄ visibility: hidden; μ μ¨μΌ ν©λλ€.
display μ¬μ© μμ
1. display: block;
<html>
1
2
3
|
<span>inline</span>
<span>inline</span>
<span class="block">display: block</span>
|
cs |
<css>
1
2
3
4
5
6
7
8
9
|
span {
background-color: yellow;
border: 1px solid black;
}
.block {
display: block;
width: 200px;
}
|
cs |
<μ€νκ²°κ³Ό>
2. display: inline;
<html>
1
2
3
|
<div>block</div>
<div>block</div>
<div class="inline">display: inline</div>
|
cs |
<css>
1
2
3
4
5
6
7
8
|
div {
background-color: yellow;
border: 1px solid black;
}
.inline {
display: inline;
}
|
cs |
<μ€νκ²°κ³Ό>
3. display: inline-block;
<html>
1
2
3
|
<span>inline</span>
<span>inline</span>
<span class="inline-block">display: inline-block</span>
|
cs |
<css>
1
2
3
4
5
6
7
8
9
10
|
span {
background-color: yellow;
border: 1px solid black;
}
.inline-block {
display: inline-block;
width: 200px;
height: 100px;
}
|
cs |
<μ€νκ²°κ³Ό>
4. display: none;
<html>
1
2
3
4
|
<div class="none">display - none</div>
<div>div</div>
<div class="hidden">visibility - hidden</div>
<div>div</div>
|
cs |
<css>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
div {
background-color: yellow;
border: 1px solid black;
width: 100px;
height: 100px;
}
.none {
display: none;
}
.hidden {
visibility: hidden;
}
|
cs |
<μ€νκ²°κ³Ό>
μμ λ§νλ κ²μ²λΌ, display: none;μ μΉνμ΄μ§μμ μμλ₯Ό μμ μ§μλ²λ¦¬μ§λ§(κ³΅κ° ν λΉ X) visibility: hidden;μ μΉνμ΄μ§μμ μμκ° λ³΄μ΄μ§ μκ²(κ³΅κ° ν λΉ O) ν΄μ€λλ€.
곡λΆν κ²μ μ 리ν λ΄μ©μ λλ€. μμ ν κ²μ΄ μμΌλ©΄ μλ €μ£Όμλ©΄ κ°μ¬νκ² μ΅λλ€ :)