Accordion / 002 — カード型|Card Style
デザイン見本
- Card-like appearance
- Shadow effects for depth
- Modern design
柔らかな影と角丸が特徴的なカード型アコーディオン。 コンテンツが浮き上がっているような表現で、クリックしたくなるインタラクションを提供します。モダンなUIに最適です。
実装コード
HTML
<div class="container">
<div class="btn-box">
<button data-default-text="Card Style Accordion" data-open-text="Close">Card Style Accordion</button>
</div>
<div class="more">
<ul>
<li>Card-like appearance</li>
<li>Shadow effects for depth</li>
<li>Modern design</li>
</ul>
</div>
</div>
CSS
/* アニメーション定義 */
@keyframes acc2-fadeIn {
0% {
opacity: 0;
transform: translateY(-10px)
}
100% {
opacity: 1;
transform: none
}
}
.container {
width: 100%;
}
.container .btn-box button {
width: 100%;
padding: 16px 20px;
background: #fff;
border: none;
border-radius: 12px;
font-size: 14px;
font-weight: 600;
color: #333;
cursor: pointer;
transition: all 0.3s ease;
text-align: left;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.container .btn-box button:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}
.container .more {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
background: #fff;
border-radius: 0 0 12px 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
margin-top: 0;
position: relative;
}
.container .more.appear {
max-height: 200px;
margin-top: -12px;
animation: acc2-fadeIn 0.3s ease;
}
.container .more ul {
list-style: none;
padding: 20px 16px 14px;
margin: 0;
}
.container .more li {
padding: 8px 0;
color: #666;
border-bottom: 1px solid #eee;
font-size: 13px;
}
.container .more li:last-child {
border-bottom: none;
}
JS
document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll('.container').forEach(container => {
const button = container.querySelector('.btn-box button');
const content = container.querySelector('.more');
if (button && content) {
button.addEventListener('click', function() {
content.classList.toggle('appear');
// ボタンテキストの切り替え
if (content.classList.contains('appear')) {
this.textContent = this.dataset.openText || 'Close';
} else {
this.textContent = this.dataset.defaultText;
}
});
}
});
});