π¨ float μμ± μ¬μ©λ² νλ°© μ 리
CSS Float
float νλ‘νΌν°λ ν΄λΉ μμλ₯Ό λ€μ μμ μμ λ μκ² νλ€. μ¬κΈ°μ λ μλ€(float)λ μλ―Έλ μμκ° κΈ°λ³Έ λ μ΄μμ νλ¦μμ λ²μ΄λ μμμ λͺ¨μλ¦¬κ° νμ΄μ§μ μΌμͺ½μ΄λ μ€λ₯Έμͺ½μ μ΄λνλ κ²μ΄λ€. κ·Έλμ λ³΄ν΅ λ μ΄μμμ ꡬμ±ν λ μμλ₯Ό κ°λ‘ μ λ ¬νκΈ° μν΄ μ¬μ©λλ κΈ°λ²μ΄λ€. μλ₯Ό λ€μ΄, λ¬Έμμ μ¬μ§κ³Ό κ·Έλ¦Όμ΄ μμ λ, κ·Έλ¦Όμ μΌμͺ½μ΄λ μ€λ₯Έμͺ½μΌλ‘ λμμ μ λ ¬ νκ±°λ κ° κ°μ²΄λ₯Ό μ€λ₯Έμͺ½μ΄λ μΌμͺ½μΌλ‘ μ λ ¬νμ¬ μ 체 λ¬Έμλ₯Ό λ°°μΉ(layout)ν λλ μ¬μ©ν μ μλ€
float μμ±
νλ‘νΌν°κ° | Description |
none | μμλ₯Ό λ μκ² νμ§ μλλ€. (κΈ°λ³Έκ°) |
right | μμλ₯Ό μ€λ₯Έμͺ½μΌλ‘ μ΄λμν¨λ€ |
left | μμλ₯Ό μΌμͺ½μΌλ‘ μ΄λμν¨λ€. |
μ¬μ©λ²μ κ°λ¨νλ€. λΆμ νκ² νκ³ μΆμ μμμ float: left νλ‘νΌν°λ₯Ό μ¬μ©νλ©΄ μΌμͺ½λΆν° κ°λ‘ μ λ ¬λκ³ , float: right νλ‘νΌν°λ₯Ό μ¬μ©νλ©΄ μ€λ₯Έμͺ½λΆν° κ°λ‘ μ λ ¬λλ€.
img {
float: left;
}
float μ·¨μ
clear μμ±
CSSμ clear μμ±μ λ³λμ μμ±μΌλ‘μ, μ£Όμ κΈ°λ₯μ float μμ±μ΄ μ μ©λ μμ λ€μμ μμΉνλ μμλ€μ΄ float μμ±μ΄ μ μ©λ μμμ κ²ΉμΉλ νμμ λ°©μ§νκΈ° μν΄ μ¬μ©λλ€. μμμ float μμ±μ΄ μ μ©λλ©΄ κ·Έ μ΄νμ λ±μ₯νλ λͺ¨λ μμλ€μ μ νν μμΉλ₯Ό μ€μ νκΈ°κ° λ§€μ° νλ€μ΄ μ§κ² λλλ°, λ°λΌμ clear μμ±μ μ¬μ©νμ¬, μ΄νμ μμλ€μ΄ λλ float μμ±μ μν₯μ λ°μ§ μλλ‘ μ€μ ν΄μ£Όμ΄ μμλ€μ΄ float μμ±μ΄ μ μ©λ μμ μλμ μμΉνλλ‘ νλ€.
clear μμ±μλ float μμ±κ³Ό κ°μ΄ left, right, both, none κ°μ΄ μλ€.
νλ‘νΌν°κ° | Description |
none | clearλ₯Ό μ€μ νμ§ μμ κΈ°λ³Έκ°. μμκ° μ΄λ μͺ½μΌλ‘λ λΆμ ν μ μλ€. |
right | float: right λ₯Ό μ·¨μμν΄ μμκ° μΌμͺ½μ λΆμ ν μμ λ€μμ μμΉνλλ‘ νλ€. |
left | float :left λ₯Ό μ·¨μμν΄ μμκ° μ€λ₯Έμͺ½μ λΆμ ν μμ λ€μμ μμΉνλλ‘ νλ€. |
both | float:left , float:right λλ€ μ·¨μμν΄ μμκ° μΌμͺ½κ³Ό μ€λ₯Έμͺ½μ λΆμ ν μμ λ€μμ μμΉνλλ‘ νλ€. |
μλ₯Όλ€μ΄ μλ μμ μ κ°μ΄ μ΄λ―Έμ§μ float: right μμ±μ μ£Όκ²λλ©΄ μ΄λ―Έμ§λ μ€λ₯Έμͺ½μ λ°°μΉλκ³ κ·Έ λ€μ λ¬Έλ¨ μμλ μλμΌλ‘ μΌμͺ½μ λ°°μΉλκ² λλ€.
<div>
<img src="https://taegon.kim/wp-content/uploads/2018/05/image-5.png">
</div>
<p>
Lorem Ipsum is simply dummy text of ...
</p>
img {
float: right;
width: 25%;
}
λ§μΌ λ¬Έλ¨ μμμ μ΄λ―Έμ§ μλμ μμΉνλλ‘ νκ³ μΆλ€λ©΄ float: right λ₯Ό μ·¨μμν€λ clear: left λ₯Ό μ§μ ν΄μ£Όλ©΄ λλ€.
img {
float: right;
width: 25%;
}
p {
clear: right; // p νκ·Έλ floatμμ±μ μν₯μ λ°μ§ μμ
}
float μ¬μ©μ μ£Όμμ¬ν
float νλ‘νΌν°λ₯Ό μ¬μ©ν λ μμμ μμΉλ₯Ό κ³ μ μν€λ position νλ‘νΌν°μ absoluteλ₯Ό μ¬μ©νλ©΄ μλλ€. float μμ±μ΄ relativeν μμΉ μ§μ μ νκΈ° λλ¬Έμ position: absolute μμ±μ΄ μ μ©λμ§ μκΈ° λλ¬Έμ΄λ€.
λν float μμ±μ μ¬μ©νλ©΄ ν΄λΉ μμλ μΌλ°μ μΈ νλ¦μμ λ²μ΄λκ² λμ΄ μμμ λΆλͺ¨ μμλ ν΄λΉ μμμ λμ΄λ₯Ό μΈμνμ§ λͺ»νκ² λλλ°, μ΄ κ²½μ° λΆλͺ¨ μμμ overflow: hidden μμ±μ μΆκ°νμ¬ ν΄κ²°ν μ μλ€.
float μμ±μ μ΄μ©ν λ μ΄μμ
float μμ±μ μ΄μ©νλ©΄ μμλ€μ μ’μ°λ‘ λΆμ μμΌμ λ°°μΉν μ μκΈ° λλ¬Έμ μμ μλ float μμ±μ μ΄μ©νμ¬ λ μ΄μμμ ꡬμ±νλ κ²μ΄ μΌλ°μ μ΄μλ€. νμ§λ§ float μμ±μ μμλ€μ΄ λΆμ νλ©΄μ λ€λ₯Έ μμλ€κ³Ό κ²ΉμΉκΈ°λ νκ³ , λμ΄λ₯Ό μλμΌλ‘ κ³μ°νμ§ λͺ»νλ λ±μ λ¬Έμ μ μ΄ μμ΄μ, νμ¬λ flexboxλ CSS Gridμ κ°μ λ μ΄μμ κΈ°μ μ μ΄μ©νμ¬ λμ± ν¨μ¨μ μ΄κ³ λ€μν λ μ΄μμμ ꡬμ±νκ³ μμ΄ μ°Έκ³ μ λλ‘λ§ λ³΄μ
<h1>float μμ±μ μ΄μ©ν λ μ΄μμ</h1>
<div class="page">
<header>
<h2>header μμ</h2>
</header>
<nav>
<h2>nav μμ</h2>
<p>μ¬κΈ°μλ λ³΄ν΅ λ©λ΄κ° λ€μ΄κ°λλ€.</p>
</nav>
<section>
<h2>section μμ</h2>
<p>μ¬κΈ°μλ νμ΄μ§μ ν΄λΉνλ λ΄μ©μ΄ λ€μ΄κ°λλ€.<br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ornare sapien suscipit tincidunt ullamcorper. Cras ac sem sed mauris maximus rhoncus vel in metus. Nam pharetra arcu sit amet dolor interdum, eget scelerisque libero finibus. Phasellus quis vulputate ante. Fusce sit amet viverra justo. Donec id elementum mauris. Nam id porttitor nisl, et suscipit nunc. Vestibulum sit amet volutpat quam. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis placerat sem eu facilisis ultricies.
</p>
</section>
<footer>
<h2>footer μμ</h2>
</footer>
</div>
div.page {
border: 3px solid #CD5C5C;
overflow: auto;
}
h2 { text-align: center; }
header { border: 3px solid #FFD700; }
nav {
border: 3px solid #FF1493;
width: 150px;
float: left; // λ€λΉκ²μ΄μ
μ μΌμͺ½ μμΉ
}
section {
border: 3px solid #00BFFF;
margin-left: 156px;
}
footer{ border: 3px solid #00FA9A; }
See the Pen float layout by barzz12 (@inpaSkyrim) on CodePen.
# μ°Έκ³ μλ£
https://tcpschool.com/css/css_position_float
https://css-tricks.com/all-about-floats/
https://poiemaweb.com/css3-float