<오늘부터 CSS 마스터 19일차> Accordion 2023/03/17 카테고리 CSS Accordion 1. HTML 마크업 설계1234567891011121314<button class="accordion">Section 1</button><div class="panel"> <p>Lorem ipsum...</p></div><button class="accordion">Section 2</button><div class="panel"> <p>Lorem ipsum...</p></div><button class="accordion">Section 3</button><div class="panel"> <p>Lorem ipsum...</p></div> 2. CSS 스타일링12345678910111213141516171819202122232425262728.accordion { background-color: #eee; color: #444; cursor: pointer; padding: 18px; width: 100%; text-align: left; border: none; outline: none;}/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */.accordion:hover { background-color: #ccc;}/* Style the accordion panel. Note: hidden by default */.panel { padding: 0 18px; background-color: white; max-height: 0; overflow: hidden; transition: max-height 0.4s ease-out;}.active { max-height: 100vh;} 3. React 로직12345678910111213141516171819// Accordion.jsximport { useState } from "react";import "./styles/main.css";function Accordion({ title, info }) { const [showInfo, setShowInfo] = useState(false); return ( <> <button className="accordion" onClick={() => setShowInfo(!showInfo)}> {title} </button> <div className={`panel ${showInfo ? "active" : ""}`}> <p>{info}</p> </div> </> );}export default Accordion; 댓글 공유