Menu
Coddy logo textTech

인터랙티브 FAQ 아코디언

Coddy HTML 여정의 JavaScript in Action 섹션에 포함된 레슨 — 27개 중 24번째.

challenge icon

챌린지

쉬움

우리는 몇 가지 질문이 있는 간단한 FAQ 페이지를 가지고 있습니다. 이러한 유형의 디자인은 매우 일반적입니다. 사용자가 질문을 클릭하면 숨겨진 답변이 부드럽게 아래로 내려와야 합니다. 동시에 "+" 기호를 "×"로 회전시켜 섹션이 열려 있음을 보여줄 수 있습니다.

하나의 질문이 있는 FAQ 섹션이 있습니다. 여러분의 임무는 이를 대화형으로 만드는 것입니다:

JavaScript에서:

  • FAQ 질문에 클릭 이벤트 리스너를 추가합니다.
  • 클릭했을 때, 답변의 "show" 클래스를 토글합니다.

CSS에서:
다음과 같이 스타일을 추가합니다:

  • FAQ 답변에 "show" 클래스가 있을 때, opacity를 1로, max-height를 300px로 설정합니다.

직접 해보기

<!DOCTYPE html>
<html>
<head>
  <title>FAQ Challenge</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
   <h1>FAQ – Healthy Lifestyle</h1>
  <div class="faq">
    <div class="faq-item">
      <div class="faq-question">
        <span>What does a balanced diet mean?</span>
        <span>+</span>
      </div>
      <div class="faq-answer">
        A balanced diet includes a variety of foods — fruits, vegetables, whole grains, lean proteins, and healthy fats — in the right proportions to keep your body nourished and energized.
      </div>
    </div>
  </div>
 <script src="script.js"></script>
</body>
</html>

JavaScript in Action의 모든 레슨