본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

그리드 컬럼

원문 보기 위키 갱신

그리드 컬럼 (Grid Column)

Flexbox 소개 이론을 미리 읽으셨기를 바라며, 이제 Column에 대해 더 깊이 알아볼게요.

동일한 높이의 행을 위해 브레이크포인트별 row 클래스를 활용하세요. 필요한 각 브레이크포인트에 단위 없는 클래스를 몇 개든 추가하면 모든 행이 같은 높이가 돼요.

출처: 문서

본문

동일 높이 (Equal-height)

예를 들어, xs부터 xl까지 모든 장치와 뷰포트에 적용되는 두 가지 그리드 레이아웃이 있어요.

예시 "Equal Height Example":

<template>
  <div class="example-column-equal-width">
    <div class="column" style="height: 150px">
      <div class="col"> 1 of 2 </div>
      <div class="col"> 1 of 2 </div>
    </div>

    <div class="column" style="height: 150px">
      <div class="col"> 1 of 3 </div>
      <div class="col"> 1 of 3 </div>
      <div class="col"> 1 of 3 </div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-equal-width
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

하나의 행 높이 설정하기 (Setting one row height)

flexbox 그리드 행에 대한 자동 레이아웃은, 한 행의 높이를 설정하면 다른 행들이 그 주위에서 자동으로 크기를 조정한다는 뜻이기도 해요. 미리 정의된 그리드 클래스(아래와 같음)나 인라인 높이를 사용할 수 있어요. 가운데 행의 높이와 무관하게 다른 행들이 크기를 조정한다는 점에 주목하세요.

<template>
  <div class="example-column-row-width">
    <div class="column" style="height: 150px">
      <div class="col"> .col </div>
      <div class="col-5"> .col-5 </div>
      <div class="col"> .col </div>
    </div>

    <div class="column" style="height: 250px">
      <div class="col"> .col </div>
      <div class="col-8"> .col-8 </div>
      <div class="col"> .col </div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-row-width
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

가변 높이 콘텐츠 (Variable height content)

col-{breakpoint}-auto 클래스를 사용하면 행이 콘텐츠의 자연스러운 높이에 따라 스스로 크기를 정할 수 있어요. 입력, 숫자 같은 한 줄 콘텐츠에서 아주 유용해요. 이것을 가로 정렬 클래스와 함께 쓰면, 뷰포트 높이가 변할 때 고르지 않은 행 크기를 가진 레이아웃을 중앙에 배치하는 데 아주 유용해요.

<template>
  <div class="example-column-variable-height">
    <div class="column justify-center" style="height: 250px">
      <div class="col col-md-4"> .col .col-md-4 </div>
      <div class="col-auto"> .col-auto (Variable height content) </div>
      <div class="col col-md-4"> .col .col-md-4 </div>
    </div>

    <div class="column" style="height: 250px">
      <div class="col"> .col </div>
      <div class="col-auto"> .col-auto (Variable height content) </div>
      <div class="col col-md-3"> .col .col-md-3 </div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-variable-height
  .column
    background: rgba(#aa0, .1)
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

반응형 클래스 (Responsive classes)

그리드는 복잡한 반응형 레이아웃을 구축하기 위한 다섯 단계의 미리 정의된 클래스를 포함해요. 초소형, 소형, 중형, 대형 또는 초대형 장치에서 행의 크기를 원하는 대로 커스터마이즈하세요.

모든 브레이크포인트 (All breakpoints)

가장 작은 장치부터 가장 큰 장치까지 동일한 그리드에는 .col과 .col-* 클래스를 사용하세요. 특히 크기가 필요한 행에는 숫자 클래스를 지정하고, 그 외에는 .col로 두면 돼요.

<template>
  <div class="example-column-all-breakpoints">
    <div class="column" style="height: 150px">
      <div class="col">.col</div>
      <div class="col">.col</div>
      <div class="col">.col</div>
      <div class="col">.col</div>
    </div>

    <div class="column" style="height: 150px">
      <div class="col-8">.col-8</div>
      <div class="col-4">.col-4</div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-all-breakpoints
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

섞어 맞추기 (Mix and match)

일부 그리드 단계에서 행을 그냥 쌓고 싶지 않나요? 각 단계에 필요한 대로 서로 다른 클래스 조합을 사용하세요. 아래 예시를 보면 어떻게 동작하는지 더 잘 알 수 있어요.

<template>
  <div class="example-column-mix-and-match">
    <!-- 모바일에서 컬럼을 쌓으려면 하나는 전체 너비, 다른 하나는 반 너비로 -->
    <div class="column" style="height: 150px">
      <div class="col col-md-8">.col .col-md-8</div>
      <div class="col-6 col-md-4">.col-6 .col-md-4</div>
    </div>

    <!-- 컬럼은 모바일에서 33.3%로 시작해 데스크톱에서 50%로 올라감 -->
    <div class="column" style="height: 150px">
      <div class="col-4 col-md-6">.col-4 .col-md-6</div>
      <div class="col-4 col-md-6">.col-4 .col-md-6</div>
      <div class="col-4 col-md-6">.col-4 .col-md-6</div>
    </div>

    <!-- 컬럼은 모바일과 데스크톱 모두에서 항상 50% 너비 -->
    <div class="column" style="height: 150px">
      <div class="col-6">.col-6</div>
      <div class="col-6">.col-6</div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-mix-and-match
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

정렬 (Alignment)

flexbox 정렬 유틸리티를 사용해 컬럼을 세로와 가로로 정렬하세요.

예시 "가로 정렬 (Horizontal alignment)":

<template>
  <div class="example-column-horizontal-alignment">
    <q-badge>items-start</q-badge>
    <div class="column items-start" style="height: 150px">
      <div class="col"> One of three rows </div>
      <div class="col"> One of three rows </div>
      <div class="col"> One of three rows </div>
    </div>

    <q-badge>items-center</q-badge>
    <div class="column items-center" style="height: 150px">
      <div class="col"> One of three rows </div>
      <div class="col"> One of three rows </div>
      <div class="col"> One of three rows </div>
    </div>

    <q-badge>items-end</q-badge>
    <div class="column items-end" style="height: 150px">
      <div class="col"> One of three rows </div>
      <div class="col"> One of three rows </div>
      <div class="col"> One of three rows </div>
    </div>

    <q-badge>self-*</q-badge>
    <div class="column" style="height: 150px">
      <div class="col self-start"> .self-start </div>
      <div class="col self-center"> .self-center </div>
      <div class="col self-end"> .self-end </div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-horizontal-alignment
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  > div + div
    margin-top: 1rem
  .column
    background: rgba(#aa0, .1)
</style>

예시 "세로 정렬 (Vertical alignment)":

<template>
  <div class="example-column-vertical-alignment">
    <q-badge>justify-start</q-badge>
    <div class="column justify-start" style="height: 150px">
      <div class="col-4"> One of two rows </div>
      <div class="col-4"> One of two rows </div>
    </div>

    <q-badge>justify-center</q-badge>
    <div class="column justify-center" style="height: 150px">
      <div class="col-4"> One of two rows </div>
      <div class="col-4"> One of two rows </div>
    </div>

    <q-badge>justify-end</q-badge>
    <div class="column justify-end" style="height: 150px">
      <div class="col-4"> One of two rows </div>
      <div class="col-4"> One of two rows </div>
    </div>

    <q-badge>justify-around</q-badge>
    <div class="column justify-around" style="height: 150px">
      <div class="col-4"> One of two rows </div>
      <div class="col-4"> One of two rows </div>
    </div>

    <q-badge>justify-between</q-badge>
    <div class="column justify-between" style="height: 150px">
      <div class="col-4"> One of two rows </div>
      <div class="col-4"> One of two rows </div>
    </div>

    <q-badge>justify-evenly</q-badge>
    <div class="column justify-evenly" style="height: 150px">
      <div class="col-4"> One of two rows </div>
      <div class="col-4"> One of two rows </div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-vertical-alignment
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  > div + div
    margin-top: 1rem
  .column
    background: rgba(#aa0, .1)
</style>

[!TIP] items-center + justify-center와 동등한 편의용 flex-center CSS 클래스도 있어요. flex, row 또는 column과 함께 사용하세요.

래핑 (Wrapping)

단일 행 안에 12개 이상의 컬럼을 배치하면, 추가 컬럼들의 각 묶음이 하나의 단위로 새 줄에 래핑돼요.

<template>
  <div class="example-column-row-wrapping">
    <div class="column" style="height: 300px; max-height: 100%">
      <div class="col-9">.col-9</div>
      <div class="col-5">
        .col-5
        <br />Since 9 + 5 = 14 &gt; 12, this 5-row-wide div <br />gets wrapped
        onto a new line as one <br />contiguous unit.
      </div>
      <div class="col-6">
        .col-6
        <br />Subsequent rows <br />continue along the <br />new line.
      </div>
    </div>

    <div class="column" style="height: 150px">
      <div class="col-3 col-sm-6">.col-3 .col-sm-6</div>
      <div class="col-3 col-sm-6">.col-3 .col-sm-6</div>

      <div class="col-3 col-sm-6">.col-3 .col-sm-6</div>
      <div class="col-3 col-sm-6">.col-3 .col-sm-6</div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-row-wrapping
  .column
    background: rgba(#aa0, .1)
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

재정렬 (Reordering)

예시 "Reverse":

<template>
  <div class="example-column-reverse">
    <div class="column reverse" style="height: 150px">
      <div class="col"> First, but last </div>
      <div class="col"> Second, unchanged </div>
      <div class="col"> Third, but first </div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-reverse
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

예시 "Flex order":

<template>
  <div class="example-column-flex-order">
    <div class="column" style="height: 190px">
      <div class="col order-none">
        First, but unordered
        <br />(.order-none)
      </div>
      <div class="col order-last">
        Second, but last
        <br />(.order-last)
      </div>
      <div class="col order-first">
        Third, but first
        <br />(.order-first)
      </div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-flex-order
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

중첩 (Nesting)

콘텐츠를 기본 그리드로 중첩하려면, 기존 .col-sm-* 컬럼 안에 새 .row와 .col-sm-* 컬럼 세트를 추가하세요. 중첩된 행은 합이 12 이하가 되는 컬럼 세트를 포함해야 해요(12개 컬럼을 모두 사용할 필요는 없어요).

<template>
  <div class="example-column-nesting">
    <div class="column" style="height: 200px">
      <div class="col-auto">.col-auto</div>
      <div class="col column">
        <div class="col-8 col-sm-6"> .col-8 .col-sm-6 </div>
        <div class="col-4 col-sm-6"> .col-4 .col-sm-6 </div>
      </div>
    </div>
  </div>
</template>

<style lang="sass">
.example-column-nesting
  .column > div
    padding: 10px 15px
    background: rgba(#999, .15)
    border: 1px solid rgba(#999, .2)
  .column + .column
    margin-top: 1rem
</style>

Flex 그리드 플레이그라운드 (Flex Grid Playground)

Flex를 실제로 보려면 Flex Playground를 사용해서 상호작용하며 더 배울 수 있어요.

Flex Playground

더 알아보기 (Learn more)

Grid Column은 column + col-* 클래스로 동일 높이 행, 가변 높이 콘텐츠, 반응형 분할, 정렬, 래핑, 재정렬, 중첩을 구현해요. col-{bp}-auto, offset-*, order-* 등을 조합해 유연한 레이아웃을 만들 수 있어요.