- νλ μ€ λ°μ€ λ μ΄μμμ 1μ°¨μ λ°©μμΌλ‘ ν¨κ³Όμ μΈ λ μ΄μμμ μ€κ³ν μ μλλ‘ κ³ μλ μ€νμΌ μ λλ€.
- 1μ°¨μ λ°©μμ΄λ, κ°λ‘(row) νΉμ μΈλ‘(column)μ€ ν λ°©ν₯μΌλ‘λ§ λ μ΄μμμ μ€κ³νλ λ°©μμ λ§ν©λλ€.
νλ μ€ λ°μ€ λ μ΄μμ
ꡬμ±μμ
- μ£ΌμΆ(main axis) : νλ μ€ λ°μ€μ μ§ν λ°©ν₯κ³Ό μνν μΆμ μλ―Έ
- κ΅μ°¨μΆ(cross axis) : μ£ΌμΆκ³Ό μμ§ν μΆμ μλ―Έ
- νλ μ€ μ»¨ν μ΄λ : display μμ±κ°μΌλ‘ flexλ inline-flexκ° μ μ©λ μμλ₯Ό μλ―Έ
- νλ μ€ μμ΄ν : νλ μ€ μ»¨ν μ΄λμ μμ κ΄κ³λ₯Ό μ΄λ£¨λ νκ·Έ κ΅¬μ± μμλ₯Ό μλ―Έ
λ μ΄μμ νμΈ λ°©λ²
νλ μ€ λ°μ€ λ μ΄μμμ κΈ°λ³Έ μμ±
display μμ±
display: flex; / inline-flex;
π flex
λ μ μ©λ μμμ λ€μ μμκ° νμ μ€ λ°κΏλκ³ , inline-flex
λ λ€μ μμκ° μ£Όλ³μ λ°°μΉ
π display
μμ±μ΄ μ§μ λ μμλ νλ μ€ μ»¨ν
μ΄λ
κ° λκ³ , μμ μμλ νλ μ€ μμ΄ν
μ΄ λ©λλ€.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<title>flex box</title>
<style>
.flex-container {
width: 300px;
height: 200px;
background-color:bisque;
border: 1px solid black;
display: flex;
}
.flex-item {
width: 80px;
height: 50px;
margin: 2px;
text-align: center;
border: 1px solid darkblue;
color: white;
background-color: orange;
}
.flex-item:nth-child(2n) {
background-color: orangered;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-item">item1</div>
<div class="flex-item">item2</div>
<div class="flex-item">item3</div>
<div class="flex-item">item4</div>
</div>
</body>
</html>
flex-direction μμ±
πνλ μ€ λ°μ€ λ μ΄μμμ μ£ΌμΆ λ°©ν₯(μ§ν λ°©ν₯)μ κ²°μ ν©λλ€.
flex-direction: μμ±κ°;
flex-wrap μμ±
π νλ μ€ μμ΄ν μ΄ μ»¨ν μ΄λ μμμ λ²μ΄λ λ μ΄λ»κ² μ²λ¦¬ ν μ§ κ²°μ ν©λλ€.
flex-wrap: μμ±κ°;
π κΈ°λ³Έ κ°μ nowrap
μ
λλ€. (μΌμ ν ν¬κΈ°κΉμ§ μ°κ·Έλ¬μ§λ€κ° λ μ΄μ 곡κ°μ΄ μμΌλ©΄ λμ΄κ°)
nowrap
wrap
flex-flow μμ±
π flex-direction
μμ±κ³Ό flex-wrap
μμ±μ ν λ²μ μ¬μ©ν μ μμ΅λλ€.
flex-flow: [flex-direction μμ±] [flex-wrap μμ±];
flex-flow: column nowrap;
νλ μ€ λ°μ€ λ μ΄μμμ μ λ ¬ μμ±
justify-content μμ±
π νλ μ€ μμ΄ν μ μ£ΌμΆ λ°©ν₯μΌλ‘ μ λ ¬ν λ μ¬μ©νλ μμ±
justify-content: μμ±κ°;
CSS
.flex-container {
width: 300px;
height: 200px;
background-color:bisque;
border: 1px solid black;
display: flex;
flex-flow: row wrap;
justify-content: flex-start;
}
.flex-item {
width: 80px;
border: 1px solid darkblue;
color: white;
background-color: orange;
display: flex;
justify-content: center;
align-items: center;
}
.flex-item:nth-child(2n) {
background-color: orangered;
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<title>flex box</title>
</head>
<body>
<div class="flex-container">
<div class="flex-item">item1</div>
<div class="flex-item">item2</div>
<div class="flex-item">item3</div>
<div class="flex-item">item4</div>
<div class="flex-item">item5</div>
<div class="flex-item">item6</div>
<div class="flex-item">item7</div>
<div class="flex-item">item8</div>
<div class="flex-item">item9</div>
</div>
</body>
</html>
flex-start
center
space-between
π μμ΄ν μ¬μ΄μ κ°κ²©μ μΌμ νκ² μ μ§νμ§λ§ μμ΄ν κ³Ό 컨ν μ΄λ μ¬μ΄λ κ³ λ €νμ§ μμ
space-evenly
align-items, align-content, align-self μμ±
π align-items μμ±μ νλ μ€ μμ΄ν κ΅μ°¨μΆ λ°©ν₯μΌλ‘ μ λ ¬ν λ μ¬μ©
π νλ μ€ λ°μ€ λ μ΄μμμ κΈ°λ³ΈμΌλ‘ align-items μμ±μ stretch κ°μ΄ μ μ©λμ΄ μμ΅λλ€.
π κ·Έλμ λ¨μνκ² μμ±μ flexλ inline-flexλ§ μ μ©ν΄λ μμ΄ν μ΄ μ»¨ν μ΄λ λμ΄λ§νΌ κ°λ μ°Ήλλ€.
stretch
flex-start
center
μ°μ΅λ¬Έμ - navi λ° λ§λ€κΈ°
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
/* κΈ°λ³Έ μ€νμΌ μ΄κΈ°ν */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* λ€λΉκ²μ΄μ
λ° μ€νμΌ */
.navbar {
display: flex;
justify-content: space-around;
align-items: center;
background-color: #333;
padding: 1rem;
}
.navbar a {
text-decoration: none;
color: white;
font-size: 1.2rem;
}
.navbar a:hover {
color: #aaa
}
</style>
</head>
<body>
<nav class="navbar">
<a href="#">λ©λ΄1</a>
<a href="#">λ©λ΄2</a>
<a href="#">λ©λ΄3</a>
<a href="#">λ©λ΄4</a>
</nav>
</body>
</html>
λΆλͺ¨ μμ±(container)
container(λΆλͺ¨) μμ±
- display: flex κ°λ‘λ‘ λ°°μΉλ¨ (μ΅λν νΉμ±)
- display: inline-flex κ°λ‘λ‘ λ°°μΉλμ§λ§ inline νΉμ±μ κ°μ§ (μ΅μν νΉμ±)
- flex-direction: μν, μμ§ κ·Έλ¦¬κ³ μμ μμΉμ λ°©ν₯μ κ²°μ ν¨.
row, row-reverse, column, column-reverse - flex-wrap: λ¬Άμ μ¬λΆλ₯Ό κ²°μ (μ€λ°κΏ), κΈ°λ³Έκ°μ nowrap(κ³΅κ° μμΌλ©΄ λμΉ¨), wrapμ μ€λ°κΏ
- justify-content: μ£ΌμΆμ μ λ ¬ λ°©λ²μ κ²°μ ν¨
flex-start, flex-end, center, space-between, space-evenly - align-content: κ΅μ°¨μΆμ λν μ¬λ¬μ€μ λν μ λ ¬ λ°©λ²
flex-start, flex-end, center, space-between, space-around, space-evenly - align-items: κ΅μ°¨μΆμ λν ν μ€ μ λ ¬ λ°©λ²
flex-start, flex-end, center - flex-flow: flex-directionκ³Ό flex-wrapμ νκΊΌλ²μ μ§μ ν μ μλ λ¨μΆ μμ±(row wrap)
items(μμ) μμ±
- flex-grow: μ¦κ° λΉμ¨μ μ‘°μ ν¨. κΈ°λ³Έκ°μ 0
- order: μμ΄ν μ μμ μ§μ κ°λ₯, κΈ°λ³Έκ°μ 0, μ«μκ° μμ μλ‘ μμ νμ λ¨.
- flex-shrink: κ°μ λλΉ λΉμ¨ μ§μ , κΈ°λ³Έκ°μ 1, 0μΌλ‘ μ§μ νλ©΄ containerκ° μ€μ΄ λ€λλΌλ μ°κ·Έλ¬μ§μ§ μμ.
- flex-basis: κΈ°λ³Έκ°μ auto, contentμ ν¬κΈ°μ μν₯μ λ°μ, μλ°κ² ν λ €λ©΄ 0μΌλ‘ μ§μ
flex-grow μ¬μ©
body {
width: 500px;
}
.container {
background-color: royalblue;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
.container .item {
width: 100px;
height: 100px;
border: 3px dashed red;
margin: 10px;
background-color: orange;
display: flex;
justify-content:center;
align-items:center;
}
.container .item:nth-child(3) {
flex-grow: 1;
background-color: red;
border: 3px dashed black;
}
.container .item:nth-child(6) {
flex-grow: 1;
}
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
</div>
νμ μ€μμ νμνκΈ°
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>μΈλ‘λ‘ μ€μμ λ°°μΉνκΈ°</title>
<style>
* {
margin: 0;
box-sizing: border-box;
}
body {
background-image: url(./images/bg5.jpg);
background-repeat: no-repeat;
background-position: left top;
background-size: cover;
background-attachment: fixed;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
button {
background-color: #ccc;
font-size: 1.2em;
padding: 1em 2em;
border: none;
border-radius: 5px;
box-shadow: 1px 1px 2px #fff;
}
</style>
</head>
<body>
<button>ν΄λ¦</button>
</body>
</html>
μ©μ΄ μ 리
νλ μ€ λ°μ€ λ μ΄μμ
νλ μ€ λ°μ€ λ μ΄μμ κΈ°λ³Έ μμ±
νλ μ€ λ°μ€ λ μ΄μμμ μ λ ¬ μμ±
'π¨ Frontend > HTML & CSS' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
CSS β§ λ°μν μΉκ³Ό λ―Έλμ΄ μΏΌλ¦¬ (0) | 2023.03.20 |
---|---|
CSS ⦠그리λ(grid) λ μ΄μμ (0) | 2023.03.20 |
CSS β€ μΉ ν°νΈ, μμ΄μ½ ν°νΈ μ¬μ©νκΈ° + μ€μ΅μμ (0) | 2023.03.16 |
CSS β£ μ ν ν¨κ³Ό - (3) λ³ν ν¨κ³Ό(transform) (0) | 2023.03.16 |
CSS β£ μ ν ν¨κ³Ό - (2) μ λλ©μ΄μ μμ± (2) | 2023.03.15 |