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

Card

원문 보기 위키 갱신

Shoelace의 Card 컴포넌트(sl-card)는 서로 관련된 내용을 하나의 컨테이너로 묶을 때 사용해요. image·header·footer 슬롯을 제공해서 이미지, 제목, 동작 버튼 등을 카드에 깔끔하게 배치할 수 있답니다.

출처: 문서

본문

Card는 서로 관련된 주제(subjects)를 하나의 컨테이너로 묶는 데 사용할 수 있어요.

<sl-card class="card-overview">
  <img
    slot="image"
    src="https://images.unsplash.com/photo-1559209172-0ff8f6d49ff7?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=500&q=80"
    alt="A kitten sits patiently between a terracotta pot and decorative grasses."
  />
  <strong>Mittens</strong><br />
  This kitten is as cute as he is playful. Bring him home today!<br />
  <small>6 weeks old</small>
  <div slot="footer">
    <sl-button variant="primary" pill>More Info</sl-button>
    <sl-rating></sl-rating>
  </div>
</sl-card>
<style>
  .card-overview {
    max-width: 300px;
  }
  .card-overview small {
    color: var(--sl-color-neutral-500);
  }
  .card-overview [slot='footer'] {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
</style>
import SlButton from '@shoelace-style/shoelace/dist/react/button';
import SlCard from '@shoelace-style/shoelace/dist/react/card';
import SlRating from '@shoelace-style/shoelace/dist/react/rating';
const css = `
  .card-overview {
    max-width: 300px;
  }
  .card-overview small {
    color: var(--sl-color-neutral-500);
  }
  .card-overview [slot="footer"] {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
`;
const App = () => (
  <>
    <SlCard className="card-overview">
      <img
        slot="image"
        src="https://images.unsplash.com/photo-1559209172-0ff8f6d49ff7?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=500&q=80"
        alt="A kitten sits patiently between a terracotta pot and decorative grasses."
      />
      <strong>Mittens</strong>
      <br />
      This kitten is as cute as he is playful. Bring him home today!
      <br />
      <small>6 weeks old</small>
      <div slot="footer">
        <SlButton variant="primary" pill>
          More Info
        </SlButton>
        <SlRating></SlRating>
      </div>
    </SlCard>
    <style>{css}</style>
  </>
);

Examples

Basic Card

기본 카드는 특별할 건 없지만, 원하는 어떤 콘텐츠든 표시할 수 있어요.

<sl-card class="card-basic">
  This is just a basic card. No image, no header, and no footer. Just your content.
</sl-card>
<style>
  .card-basic {
    max-width: 300px;
  }
</style>
import SlCard from '@shoelace-style/shoelace/dist/react/card';
const css = `
  .card-basic {
    max-width: 300px;
  }
`;
const App = () => (
  <>
    <SlCard className="card-basic">
      This is just a basic card. No image, no header, and no footer. Just your content.
    </SlCard>
    <style>{css}</style>
  </>
);

Card with Header

헤더(header)는 제목 등을 표시하는 데 사용할 수 있어요.

<sl-card class="card-header">
  <div slot="header">
    Header Title
    <sl-icon-button name="gear" label="Settings"></sl-icon-button>
  </div>
  This card has a header. You can put all sorts of things in it!
</sl-card>
<style>
  .card-header {
    max-width: 300px;
  }
  .card-header [slot='header'] {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .card-header h3 {
    margin: 0;
  }
  .card-header sl-icon-button {
    font-size: var(--sl-font-size-medium);
  }
</style>
import SlCard from '@shoelace-style/shoelace/dist/react/card';
import SlIconButton from '@shoelace-style/shoelace/dist/react/icon-button';
const css = `
  .card-header {
    max-width: 300px;
  }
  .card-header [slot="header"] {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .card-header h3 {
    margin: 0;
  }
  .card-header sl-icon-button {
    font-size: var(--sl-font-size-medium);
  }
`;
const App = () => (
  <>
    <SlCard className="card-header">
      <div slot="header">
        Header Title
        <SlIconButton name="gear"></SlIconButton>
      </div>
      This card has a header. You can put all sorts of things in it!
    </SlCard>
    <style>{css}</style>
  </>
);

푸터(footer)는 동작(actions), 요약, 또는 그 밖의 관련 콘텐츠를 표시하는 데 사용할 수 있어요.

<sl-card class="card-footer">
  This card has a footer. You can put all sorts of things in it!
  <div slot="footer">
    <sl-rating></sl-rating>
    <sl-button variant="primary">Preview</sl-button>
  </div>
</sl-card>
<style>
  .card-footer {
    max-width: 300px;
  }
  .card-footer [slot='footer'] {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
</style>
import SlButton from '@shoelace-style/shoelace/dist/react/button';
import SlCard from '@shoelace-style/shoelace/dist/react/card';
import SlRating from '@shoelace-style/shoelace/dist/react/rating';
const css = `
  .card-footer {
    max-width: 300px;
  }
  .card-footer [slot="footer"] {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
`;
const App = () => (
  <>
    <SlCard className="card-footer">
      This card has a footer. You can put all sorts of things in it!
      <div slot="footer">
        <SlRating></SlRating>
        <SlButton slot="footer" variant="primary">
          Preview
        </SlButton>
      </div>
    </SlCard>
    <style>{css}</style>
  </>
);

Images

Card는 image 슬롯을 지원해요. 이미지는 카드의 맨 위에 표시되며, 자동으로 늘어나서 채워져요.

<sl-card class="card-image">
  <img
    slot="image"
    src="https://images.unsplash.com/photo-1547191783-94d5f8f6d8b1?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=400&q=80"
    alt="A kitten walks towards camera on top of pallet."
  />
  This is a kitten, but not just any kitten. This kitten likes walking along pallets.
</sl-card>
<style>
  .card-image {
    max-width: 300px;
  }
</style>
import SlCard from '@shoelace-style/shoelace/dist/react/card';
const css = `
  .card-image {
    max-width: 300px;
  }
`;
const App = () => (
  <>
    <SlCard className="card-image">
      <img
        slot="image"
        src="https://images.unsplash.com/photo-1547191783-94d5f8f6d8b1?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=400&q=80"
        alt="A kitten walks towards camera on top of pallet."
      />
      This is a kitten, but not just any kitten. This kitten likes walking along pallets.
    </SlCard>
    <style>{css}</style>
  </>
);

Importing

autoloader나 전통적인 loader를 사용하고 있다면 이 부분은 무시해도 돼요. 그 외의 경우 아래 스니펫 중 하나를 골라 이 컴포넌트만 골라(cherry pick) 가져올 수 있답니다.

Script / Import / Bundler / React

CDN에서 script 태그로 이 컴포넌트를 가져오려면:

<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/card/card.js"></script>

CDN에서 JavaScript import로 이 컴포넌트를 가져오려면:

import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/card/card.js';

bundler를 사용해 이 컴포넌트를 가져오려면:

import '@shoelace-style/shoelace/dist/components/card/card.js';

이 컴포넌트를 React 컴포넌트로 가져오려면:

import SlCard from '@shoelace-style/shoelace/dist/react/card';

Slots

Name Description
(default) The card’s main content.
header An optional header for the card.
footer An optional footer for the card.
image An optional image to render at the start of the card.

슬롯(slots) 사용에 대해 더 알아보기.

Custom Properties

Name Description Default
--border-color The card’s border color, including borders that occur inside the card.
--border-radius The border radius for the card’s edges.
--border-width The width of the card’s borders.
--padding The padding to use for the card’s sections.

CSS 커스텀 프로퍼티(custom properties) 커스터마이징에 대해 더 알아보기.

Parts

Name Description
base The component’s base wrapper.
image The container that wraps the card’s image.
header The container that wraps the card’s header.
body The container that wraps the card’s main content.
footer The container that wraps the card’s footer.

CSS 파트(parts) 커스터마이징에 대해 더 알아보기.

더 알아보기 (Learn more)