アコーディオン:グラデーション|Accordion: Gradient

  • 美しいグラデーション背景
  • カラフルで魅力的
  • アイコン付きボタン
  • 滑らかなアニメーション
  • 視覚的にインパクトのあるデザイン

HTML
<div class="container">
    <div class="btn-box">
        <button data-default-text="グラデーションアコーディオン" data-open-text="閉じる">グラデーションアコーディオン</button>
    </div>
    <div class="more">
        <ul>
            <li>美しいグラデーション背景</li>
            <li>カラフルで魅力的</li>
            <li>アイコン付きボタン</li>
            <li>滑らかなアニメーション</li>
            <li>視覚的にインパクトのあるデザイン</li>
        </ul>
    </div>
</div>
CSS
@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

.container {
  margin-bottom: 30px;
}

.container .btn-box button {
  width: 100%;
  padding: 20px 25px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
  position: relative;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.container .btn-box button::before {
  content: '▶';
  position: absolute;
  right: 25px;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 0.3s ease;
}

.container .btn-box button:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.6);
}

.container .more {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  border-radius: 0 0 12px 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-top: -12px;
  position: relative;
  z-index: 1;
}

.container .more.appear {
  max-height: 300px;
  animation: fadeIn 0.3s ease;
}

.container .more.appear + .btn-box button::before {
  transform: translateY(-50%) rotate(90deg);
}

.container .more ul {
  list-style: none;
  padding: 25px 20px 20px;
  margin: 0;
}

.container .more li {
  padding: 12px 0;
  color: #555;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  font-weight: 500;
}

.container .more li:last-child {
  border-bottom: none;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
  .container .btn-box button {
    font-size: 14px;
    padding: 15px 20px;
  }
  
  .container .more ul {
    padding: 15px;
  }
}
JavaScript
document.addEventListener('DOMContentLoaded', function() {
    const button = document.querySelector('.btn-box button');
    const content = document.querySelector('.more');
    
    button.addEventListener('click', function() {
        content.classList.toggle('appear');
        
        // ボタンテキストの切り替え
        if (content.classList.contains('appear')) {
            this.textContent = this.dataset.openText || '閉じる';
        } else {
            this.textContent = this.dataset.defaultText;
        }
    });
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次