π¨ CSS 4 | Flexbox (with λλ¦Όμ½λ by μ¨λ¦¬) 2ν
Step 4: Flexbox μμμκ² μ€ μ μλ μμ±λ€ (item)
HTML λ¬Έμ μμ±
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>flex-itemνΈ</title>
</head>
<body>
<div class="container">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
</div>
</body>
</html>
CSS μμ±
.container {
padding-top : 100px;
background : beige;
height: 100vh;
display : flex;
}
.item {
width: 40px;
height: 40px;
border : 1px solid black;
}
.item1 {
background-color: rgb(247, 114, 114);
}
.item2 {
background-color: rgb(250, 134, 153);
}
.item3 {
background-color: rgb(165, 100, 250);
}
- order
default κ° : 0;
μμ μμλ‘ μ§μ νκΈ°
.container {
padding-top : 100px;
background : beige;
height: 100vh;
display : flex;
}
.item {
width: 40px;
height: 40px;
border : 1px solid black;
}
.item1 {
background-color: rgb(247, 114, 114);
order : 2;
}
.item2 {
background-color: rgb(250, 134, 153);
order : 1;
}
.item3 {
background-color: rgb(165, 100, 250);
order : 3;
}
- flex-grow
default κ° : 0; μμ μ κ³ μ ν μ¬μ΄μ¦ μ μ§
flex-grow κ° μ§μ νκΈ° : νλ©΄μ΄ μ»€μ§ λ ν΄λΉ λΉμ¨λ§νΌ λμ΄λ¨
.container {
padding-top : 100px;
background : beige;
height: 100vh;
display : flex;
}
.item {
width: 40px;
height: 40px;
border : 1px solid black;
}
.item1 {
background-color: rgb(247, 114, 114);
flex-grow : 1;
}
.item2 {
background-color: rgb(250, 134, 153);
flex-grow : 2;
}
.item3 {
background-color: rgb(165, 100, 250);
flex-grow : 3;
}
- flex-shrink
default κ° : 0; μμ μ κ³ μ ν μ¬μ΄μ¦ μ μ§
flex-shrinkκ° μ§μ νκΈ° : νλ©΄μ΄ μ€μ΄λ€λ©΄μ ν΄λΉ λΉμ¨λ§νΌ μ€μ΄λ¦
.container {
padding-top : 100px;
background : beige;
height: 100vh;
display : flex;
}
.item {
width: 40px;
height: 40px;
border : 1px solid black;
}
.item1 {
background-color: rgb(247, 114, 114);
flex-grow : 1;
flex-shrink : 1;
}
.item2 {
background-color: rgb(250, 134, 153);
flex-grow : 2;
flex-shrink : 1;
}
.item3 {
background-color: rgb(165, 100, 250);
flex-grow : 3;
flex-shrink : 1;
}
νλ©΄μ΄ μ»€μ§ λ (flex-grow λΉμ¨λ‘)
νλ©΄ ν¬κΈ°κ° μ€μ΄λ€ λ (flex-shrink λΉμ¨λ‘)
- flex-basis
default κ° : auto; flex-grow, flex-shrink μ λ§κ²
flex-basis κ° μ§μ νκΈ° : flex-grow, flex-shrinkκ° μμ κ²½μ°, flex-basis μ μ§μ λ λΉμ¨λ§νΌ μ°¨μ§.
.container {
padding-top : 100px;
background : beige;
height: 100vh;
display : flex;
}
.item {
width: 40px;
height: 40px;
border : 1px solid black;
}
.item1 {
background-color: rgb(247, 114, 114);
flex-basis: 60%;
}
.item2 {
background-color: rgb(250, 134, 153);
flex-basis: 30%;
}
.item3 {
background-color: rgb(165, 100, 250);
flex-basis: 10%;
}
-align-self
default κ° : auto;
align-self : μμ΄ν λ³λ‘ μμ΄ν μ align μ§μ
.container {
padding-top : 100px;
background : beige;
height: 100vh;
display : flex;
}
.item {
width: 40px;
height: 40px;
border : 1px solid black;
}
.item1 {
background-color: rgb(247, 114, 114);
flex-basis: 60%;
align-items : center;
}
.item2 {
background-color: rgb(250, 134, 153);
flex-basis: 30%;
}
.item3 {
background-color: rgb(165, 100, 250);
flex-basis: 10%;
}
λ¨μΆν
flex : 2 2 auto /*grow, shrink, basis*/
A Complete Guide to Flexbox | CSS-Tricks
Our comprehensive guide to CSS flexbox layout. This complete guide explains everything about flexbox, focusing on all the different possible properties for the parent element (the flex container) and the child elements (the flex items). It also includes hi
css-tricks.com