--- title: flex slug: Web/CSS/flex tags: - CSS - CSS Flexible Boxes - CSS Property - Reference translation_of: Web/CSS/flex --- <div>{{CSSRef}}</div> <p><span class="seoSummary"><strong><code>flex</code></strong> <a href="/ko/docs/CSS" title="CSS">CSS</a> 속성은 하나의 플렉스 아이템이 자신의 컨테이너가 차지하는 공간에 맞추기 위해 크기를 키우거나 줄이는 방법을 설정하는 속성입니다.</span> <code>flex</code>는 {{cssxref("flex-grow")}}, {{cssxref("flex-shrink")}}, {{cssxref("flex-basis")}}의 <a href="/ko/docs/Web/CSS/Shorthand_properties">단축 속성</a>입니다.</p> <div>{{EmbedInteractiveExample("pages/css/flex.html")}}</div> <p>대부분의 경우, <code>flex</code>의 값에는 <code>auto</code>, <code>initial</code>, <code>none</code>이나 단위 없는 양의 수를 사용해야 합니다. 각 값의 적용 효과를 보려면 아래 플렉스 컨테이너의 크기를 조절해보세요.</p> <div id="flex"> <pre class="hidden brush: html"><div class="flex-container"> <div class="item auto">auto</div> <div class="item auto">auto</div> <div class="item auto">auto</div> </div> <div class="flex-container"> <div class="item auto">auto</div> <div class="item initial">initial</div> <div class="item initial">initial</div> </div> <div class="flex-container"> <div class="item auto">auto</div> <div class="item auto">auto</div> <div class="item none">none</div> </div> <div class="flex-container"> <div class="item initial">initial</div> <div class="item none">none</div> <div class="item none">none</div> </div> <div class="flex-container"> <div class="item four">4</div> <div class="item two">2</div> <div class="item one">1</div> </div> </pre> <pre class="hidden brush: css">* { box-sizing: border-box; } .flex-container { background-color: #F4F7F8; resize: horizontal; overflow: hidden; display: flex; margin: 1em; } .item { margin: 1em; padding: 0.5em; width: 110px; min-width: 0; background-color: #1B5385; color: white; font-family: monospace; font-size: 13px; } .initial { flex: initial; } .auto { flex: auto; } .none { flex: none; } .four { flex: 4; } .two { flex: 2; } .one { flex: 1; } </pre> <p>{{EmbedLiveSample("flex", 1200, 370, "", "", "example-outcome-frame")}}</p> <p>기본적으로 플렉스 아이템은 콘텐츠의 최소 너비 미만으로 줄어들지 않습니다. {{cssxref("min-width")}}나 {{cssxref("min-height")}} 값을 지정해 바꿀 수 있습니다.</p> </div> <h2 id="Syntax" name="Syntax">구문</h2> <pre class="brush: css">/* Keyword values */ flex: auto; flex: initial; flex: none; /* One value, unitless number: flex-grow */ flex: 2; /* One value, length or percentage: flex-basis */ flex: 10em; flex: 30%; /* Two values: flex-grow | flex-basis */ flex: 1 30px; /* Two values: flex-grow | flex-shrink */ flex: 2 2; /* Three values: flex-grow | flex-shrink | flex-basis */ flex: 2 2 10%; /* Global values */ flex: inherit; flex: initial; flex: unset;</pre> <p><code>flex</code> 속성은 한 개에서 세 개의 값을 사용해 지정할 수 있습니다.</p> <ul> <li><strong>값이 한 개일 때</strong>, 그 값은 다음 중 하나여야 합니다. <ul> <li>{{cssxref("<number>")}}를 지정하면 <code><flex-grow></code>입니다.</li> <li>{{cssxref("<length>")}} 또는 {{cssxref("<percentage>")}}를 지정하면 <code><flex-basis></code>입니다.</li> <li><code>none</code>, <code>auto</code>, <code>initial</code> 중 하나를 지정할 수 있습니다.</li> </ul> </li> <li><strong>값이 두 개일때</strong>, 첫 번째 값은 {{cssxref("<number>")}}여야 하며 <code><flex-grow></code>가 됩니다. 두 번째 값은 다음 중 하나여야 합니다. <ul> <li>{{cssxref("<number>")}}를 지정하면 <code><flex-shrink></code>입니다.</li> <li>{{cssxref("<length>")}}, {{cssxref("<percentage>")}}, 또는 <code>auto</code>를 지정하면 <code><flex-basis></code>입니다.</li> </ul> </li> <li><strong>값이 세 개일 때</strong>는 다음 순서를 따라야 합니다. <ol> <li><code><flex-grow></code>에 사용할 {{cssxref("<number>")}}</li> <li><code><flex-shrink></code>에 사용할 {{cssxref("<number>")}}</li> <li><code><flex-basis></code>에 사용할 {{cssxref("<length>")}}, {{cssxref("<percentage>")}}, 또는 <code>auto</code></li> </ol> </li> </ul> <h3 id="Values" name="Values">값</h3> <dl> <dt><code>initial</code></dt> <dd>아이템 크기가 각각의 <code>width</code>와 <code>height</code> 속성에 따라 정해집니다. 플렉스 컨테이너의 크기를 넘지 않기 위해 최소 크기로 줄어들 수는 있지만, 남은 공간을 채우려 늘어나지는 않습니다. <code>flex: 0 1 auto</code>와 동일합니다.</dd> <dt><code>auto</code></dt> <dd>아이템 크기가 각각의 <code>width</code>와 <code>height</code> 속성에 따라 정해집니다. 플렉스 컨테이너의 크기를 넘지 않기 위해 최소 크기로 줄어들 수 있으며, 남은 공간을 채우기 위해 늘어날 수도 있습니다. <code>flex: 1 1 auto</code>와 동일합니다.</dd> <dt><code>none</code></dt> <dd>아이템 크기가 각각의 <code>width</code>와 <code>height</code> 속성에 따라 정해지며, 컨테이너의 크기에 관계 없이 변하지 않습니다. <code>flex: 0 0 auto</code>와 동일합니다.</dd> <dt><a id="<'flex-grow'>" name="<'flex-grow'>"><code><'flex-grow'></code></a></dt> <dd>플렉스 아이템의 {{cssxref("flex-grow")}}를 지정합니다. 음수 값은 유효하지 않습니다. 생략 시 기본값은 <code>0</code>입니다.</dd> <dt><a id="<'flex-shrink'>" name="<'flex-shrink'>"><code><'flex-shrink'></code></a></dt> <dd>플렉스 아이템의 {{cssxref("flex-shrink")}}를 지정합니다. 음수 값은 유효하지 않습니다. 생략 시 기본값은 <code>1</code>입니다.</dd> <dt><a id="<'flex-basis'>" name="<'flex-basis'>"><code><'flex-basis'></code></a></dt> <dd>플렉스 아이템의 {{cssxref("flex-basis")}}를 지정합니다. <code>0</code>을 지정하려면 <code><flex-grow></code> 또는 <code><flex-shrink></code>로 읽히지 않도록 단위를 붙여야 합니다. 생략 시 기본값은 <code>auto</code>입니다.</dd> </dl> <div class="note"> <p>한 개 또는 두 개의 단위 없는 숫자 값을 사용할 때, <code><flex-basis></code>의 값은 <code>auto</code>가 아니라 <code>0</code>이 됩니다. 더 자세한 정보는 <a href="https://drafts.csswg.org/css-flexbox/#flex-common">플렉시블 박스 레이아웃 모듈</a> 초안에서 확인할 수 있습니다.</p> </div> <h3 id="형식_구문">형식 구문</h3> {{csssyntax}} <h2 id="예제">예제</h2> <pre class="brush: css">#flex-container { display: flex; flex-direction: row; } #flex-container > .flex-item { flex: auto; } #flex-container > .raw-item { width: 5rem; } </pre> <pre class="brush: html"><div id="flex-container"> <div class="flex-item" id="flex">Flex box (click to toggle raw box)</div> <div class="raw-item" id="raw">Raw box</div> </div> </pre> <div class="hidden"> <pre class="brush: js">var flex = document.getElementById("flex"); var raw = document.getElementById("raw"); flex.addEventListener("click", function() { raw.style.display = raw.style.display == "none" ? "block" : "none"; }); </pre> <pre class="brush: css">#flex-container { width: 100%; font-family: Consolas, Arial, sans-serif; } #flex-container > div { border: 1px solid #f00; padding: 1rem; } #flex-container > .raw-item { border: 1px solid #000; } </pre> </div> <h3 id="결과">결과</h3> <p>{{EmbedLiveSample('예제','100%','60')}}</p> <h2 id="Specifications" name="Specifications">명세</h2> <table class="standard-table"> <thead> <tr> <th>Specification</th> <th>Status</th> <th>Comment</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS3 Flexbox', '#flex-property', 'flex')}}</td> <td>{{Spec2('CSS3 Flexbox')}}</td> <td>Initial definition</td> </tr> </tbody> </table> <p>{{cssinfo}}</p> <h2 id="브라우저_호환성">브라우저 호환성</h2> <p>{{Compat("css.properties.flex")}}</p> <h2 id="See_also" name="See_also">같이 보기</h2> <ul> <li>CSS 플렉스박스 안내서: <em><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox">Basic Concepts of Flexbox</a></em></li> <li>CSS 플렉스박스 안내서: <em><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Controlling_Ratios_of_Flex_Items_Along_the_Main_Ax">Controlling Ratios of flex items along the main axis</a></em></li> </ul>