Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- git
- CSS
- Servlet
- 코딩테스트
- cleancode
- 그럼에도 불구하고
- 프론트엔드
- JavaScript
- 반응형 페이지
- HTML
- 그럼에도불구하고
- coding
- 자바
- 자바문제풀이
- react
- redux
- node.js
- java
- max-width
- TypeScript
- node
- 변수
- 코드업
- @media
- JS
- frontend
- github
- react-router-dom
- media query
- webpack
Archives
- Today
- Total
그럼에도 불구하고
[Visual Studio Code] Accordion 만들기 본문
Accordion을 만들어보자
accordion.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="./accordion.css"> </head> <body> <div class="area"> <div class="accordion"> <div class="accordion_item open"> <button> First accordion </button> <div class="accordion_content"> <ul> <li>list 1</li> <li>list 2</li> <li>list 3</li> <li>list 4</li> <li>list 5</li> <li>list 6</li> <li>list 7</li> <li>list 8</li> <li>list 9</li> <li>list 10</li> <li>list 11</li> </ul> </div> </div> <div class="accordion_item open"> <button> Second accordion </button> <div class="accordion_content"> <ul> <li>list 1</li> <li>list 2</li> </ul> </div> </div> </div> </div> <script src="./accordion.js" defer></script> </body> </html> | cs |
accodion.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | html { font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif; } .area { display: flex; height: 500px; width: 400px; border: 1px solid slateblue; background-color: #f0f0f0; } /* 아코디언 컴포넌트 동작 정의 */ .accordion { flex: 3 1 1px; display: flex; flex-direction: column; } /* 아코디언 아이템 닫혔을 때 */ .accordion .accordion_item { display: flex; min-height: fit-content; flex-direction: column; transition: all 0.5s; } .accordion .accordion_item>button { display: flex; padding: 1rem 1.25rem; border: none; align-items: center; font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif; border-bottom: 1px solid slateblue; overflow-anchor: none; background-color: rgb(255, 255, 255); } .accordion .accordion_item>button::after { flex-shrink: 0; width: 1.25rem; height: 1.25rem; margin-left: auto; content: ''; background-image: url(./svg/arrow_black.svg); background-repeat: no-repeat; background-size: 1.25rem; transition: transform 0.2s ease-in-out; } .accordion .accordion_item>.accordion_content { display: none; } /* 아코디언 아이템 열렸을 때 */ .accordion .accordion_item.open { flex: 1 1 1px; } .accordion .accordion_item.open>button { border: 0; color: #413533; background-color: rgb(162, 152, 224); } .accordion .accordion_item.open>button::after { transform: rotate(-180deg); } .accordion .accordion_item.open>.accordion_content { display: flex; flex: 1 1 1px; overflow-y: auto; } .accordion .accordion_item>.accordion_content::-webkit-scrollbar { width: 5px; background-color: transparent; } .accordion .accordion_item>.accordion_content::-webkit-scrollbar-track { background-color: transparent; } .accordion .accordion_item>.accordion_content::-webkit-scrollbar-thumb { height: 17%; background-color: thistle; border-radius: 10px; } ul { display: flex; flex-direction: column; height: fit-content; width: 100%; padding: 0; margin: 0; } li { display: flex; align-items: center; height: 50px; padding-left: 10px; list-style: none; border-bottom: 1px solid slateblue; background-color: #ffffff; } | cs |
accordion.js
1 2 3 4 5 6 7 8 9 10 | // 아코디언 클릭 이벤트 정의 const btns = document.querySelectorAll('.accordion .accordion_item > button'); btns.forEach(btn => { btn.addEventListener('click', (e) => { let accordion_item = e.currentTarget.parentNode; console.log("accordion_item", accordion_item); accordion_item.classList.toggle('open'); }); }); | cs |
arrow_black.svg
※ 화살표 아이콘의 경우 이 소스 코드를 그대로 사용해도 되고, 다른 걸 사용해도 무방합니다 :)
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='#212529'>
<path fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.
647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 00 1 0-.708z'/></svg>
See the Pen Untitled by zenghyun (@zenghyun) on CodePen.
'HTML, CSS > Function implementation' 카테고리의 다른 글
[Visual Studio Code] 요소 밝기 및 채도 조절하기 (0) | 2023.02.14 |
---|---|
[Visual Studio Code] input type="file" (0) | 2023.01.05 |
[Visual Studio Code] table 만들기 (0) | 2022.12.10 |
[Visual Studio Code] 여러가지 shadow 이용해보기 (0) | 2022.11.13 |
[Visual Studio Code] 가로 / 세로 메뉴바 만들기 (1) | 2022.11.13 |
Comments