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

모달 (Modal)

원문 보기 위키 갱신

시맨틱 HTML 태그 <dialog>를 사용해서, 다양한 기기와 뷰포트에서도 여백이 예쁘게 맞춰지는 클래식한 모달 컴포넌트예요. 모달은 <dialog>를 감싸는 래퍼로, <article>을 모달 콘텐츠로 사용해서 만듭니다.

출처: 문서

본문

<header> 안에 있는 <button rel="prev">는 float: right;로 정의되어 있어서, 닫기 아이콘이 제목과 상단에 정렬되도록 해줘요.

🗓️ Thank You for Registering!

We're excited to have you join us for our upcoming event. Please arrive at the museum on time to check in and get started.

Date: Saturday, April 15

Time: 10:00am - 12:00pm

<dialog open>
  <article>
    <header>
      <button aria-label="Close" rel="prev"></button>
      <p>
        <strong>🗓️ Thank You for Registering!</strong>
      </p>
    </header>
    <p>
      We're excited to have you join us for our
      upcoming event. Please arrive at the museum
      on time to check in and get started.
    </p>
    <ul>
      <li>Date: Saturday, April 15</li>
      <li>Time: 10:00am - 12:00pm</li>
    </ul>
  </article>
</dialog>

<footer> 안의 콘텐츠는 기본적으로 오른쪽 정렬돼요.

멤버십 확인하기

멤버십에 가입해 주셔서 감사합니다! 아래에서 멤버십 상세 내용을 확인해 주세요:

Membership: Individual

Price: $10

<dialog open>
  <article>
    <h2>Confirm Your Membership</h2>
    <p>
      Thank you for signing up for a membership!
      Please review the membership details below:
    </p>
    <ul>
      <li>Membership: Individual</li>
      <li>Price: $10</li>
    </ul>
    <footer>
      <button class="secondary">
        Cancel
      </button>
      <button>Confirm</button>
    </footer>
  </article>
</dialog>

데모 (Demo)

아래 버튼을 클릭하면 모달을 켜고 끌 수 있어요.

Pico는 자바스크립트 코드를 포함하지 않아요. 모달과 상호작용하려면 직접 JS를 구현해야 해요.

시작점으로 HTMLDialogElement나 아래의 고급 예제를 참고할 수 있어요:

Vanilla JavaScript

React

모달을 열려면 <dialog> 컨테이너에 open 속성을 추가하면 돼요.

유틸리티 (Utilities)

모달에는 3개의 유틸리티 클래스가 함께 제공돼요.

이 클래스들은 class-less 버전에서는 사용할 수 없어요.

.modal-is-open은 모달 아래에서의 모든 스크롤과 상호작용을 막아줘요.

<!doctype html>
<html class="modal-is-open">
  ...
</html>

.modal-is-opening은 열리는 애니메이션을 제공해요.

<!doctype html>
<html class="modal-is-open modal-is-opening">
  ...
</html>

.modal-is-closing은 닫히는 애니메이션을 제공해요.

<!doctype html>
<html class="modal-is-open modal-is-closing">
  ...
</html>

더 알아보기 (Learn more)