Accordion / 020 — シンプルボックス|Simple Box
デザイン見本
- Simple box with thin borders
- Dotted line separator
- Minimal design approach
細い枠線で囲まれたボックス型のデザイン。 展開時に現れる破線の区切り線がアクセントとなり、軽やかな印象を与えます。
実装コード
HTML
<div class="container">
<div class="btn-box">
<button data-default-text="Simple Box Accordion" data-open-text="Close">Simple Box Accordion</button>
</div>
<div class="more">
<ul>
<li>Simple box with thin borders</li>
<li>Dotted line separator</li>
<li>Minimal design approach</li>
</ul>
</div>
</div>
CSS
/* アニメーション定義 */
@keyframes acc20-fadeIn {
0% {
opacity: 0;
transform: translateY(-5px)
}
100% {
opacity: 1;
transform: translateY(0)
}
}
.container {
width: 100%;
}
.container .btn-box button {
width: 100%;
padding: 13px 16px;
background: transparent;
border: 1px solid #ddd;
font-size: 14px;
font-weight: 400;
color: #333;
cursor: pointer;
transition: all 0.3s;
text-align: left;
position: relative;
}
.container .btn-box button::after {
content: '▼';
position: absolute;
right: 16px;
top: 50%;
transform: translateY(-50%);
font-size: 11px;
color: #666;
transition: transform 0.3s;
}
.container .btn-box button:hover {
border-color: #999;
}
.container .more {
max-height: 0;
overflow: hidden;
transition: max-height 0.4s ease;
background: transparent;
border: none;
margin-top: -1px;
}
.container .more.appear {
max-height: 200px;
animation: acc20-fadeIn 0.3s ease;
border: 1px solid #ddd;
border-top: 1px dashed #ddd;
}
.container:has(.more.appear) .btn-box button::after {
transform: translateY(-50%) rotate(180deg);
}
.container:has(.more.appear) .btn-box button {
border-bottom: none;
}
.container .more ul {
list-style: none;
padding: 10px 16px;
margin: 0;
}
.container .more li {
padding: 6px 0;
color: #666;
font-size: 13px;
}
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;
}
});
}
});
});