flex-grow 초기값 및 상속 값 탐색
이 단계에서는 flex-grow 속성의 기본 동작과 상속된 동작을 조사합니다. index.html 파일을 열고 <style> 섹션을 업데이트하여 이러한 개념을 탐구합니다.
먼저, flex-grow의 초기값을 이해해 보겠습니다:
<style>
.container {
display: flex;
border: 2px solid #333;
width: 100%;
height: 200px;
}
.box {
background-color: #4caf50;
color: white;
padding: 20px;
margin: 10px;
text-align: center;
/* Initial flex-grow is 0 by default */
/* flex-grow: 0; */
}
.box1 {
/* Explicitly setting initial value */
flex-grow: 0;
}
.box2 {
/* Demonstrating inheritance */
flex-grow: inherit;
}
.box3 {
/* Another way to show initial state */
flex-grow: initial;
}
</style>
주요 관찰 사항:
flex-grow: 0;은 기본값이며, 항목이 증가하지 않음을 의미합니다.
inherit는 부모 컨테이너에서 flex-grow 값을 가져옵니다.
initial은 속성을 기본값 (0) 으로 재설정합니다.
브라우저에서 볼 때의 예시 출력:
[Three green boxes of equal width, not expanding to fill container]
더 자세히 설명하기 위해, 이러한 값의 작동 방식을 보여주도록 HTML 을 수정할 수 있습니다:
<body>
<div class="container">
<div class="box box1">Box 1 (flex-grow: 0)</div>
<div class="box box2">Box 2 (flex-grow: inherit)</div>
<div class="box box3">Box 3 (flex-grow: initial)</div>
</div>
</body>
이 예제는 기본적으로 Flex 항목이 초기 크기를 유지하고 컨테이너의 여유 공간을 채우기 위해 증가하지 않음을 보여줍니다.