CSS FAQ アコーディオンデザインジェネレーター
JavaScript不要、CSSのみで動作する「よくある質問(FAQ)」用のアコーディオンUIを生成。配色や初期状態をカスタマイズでき、コードを出力します。
プレビュー
<div class="faq-list">
<div class="faq-item">
<input type="checkbox" id="faq-1" class="faq-toggle" {{is_checked}}>
<label for="faq-1" class="faq-question">
<span class="q-icon">Q</span>
質問タイトルがここに入ります
<span class="chevron"></span>
</label>
<div class="faq-answer">
<div class="answer-inner">
<span class="a-icon">A</span>
<p>回答のテキストがここに入ります。CSSのみで開閉アニメーションを実現しています。</p>
</div>
</div>
</div>
<div class="faq-item">
<input type="checkbox" id="faq-2" class="faq-toggle" {{is_checked}}>
<label for="faq-2" class="faq-question">
<span class="q-icon">Q</span>
複数の質問を並べることができます
<span class="chevron"></span>
</label>
<div class="faq-answer">
<div class="answer-inner">
<span class="a-icon">A</span>
<p>チェックボックスのオンオフで開閉を管理しているため、JavaScriptは不要です。</p>
</div>
</div>
</div>
</div>
/* FAQ リスト */
.faq-list {
display: flex;
flex-direction: column;
gap: 16px;
width: 100%;
max-width: 800px;
margin: 0 auto;
}
.faq-item {
background-color: {{item_bg}};
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
overflow: hidden;
transition: all 0.3s ease;
border: 1px solid rgba(0, 0, 0, 0.02);
}
.faq-item:hover {
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
transform: translateY(-2px);
}
/* トグル(チェックボックス隠ぺい) */
.faq-toggle {
display: none;
}
/* 質問部分 */
.faq-question {
display: flex;
align-items: center;
padding: 24px 26px;
cursor: pointer;
font-weight: 700;
font-size: 17px;
color: {{text_color}};
position: relative;
user-select: none;
transition: background-color 0.3s ease;
}
.faq-question:hover {
background-color: rgba(0, 0, 0, 0.01);
}
.q-icon {
color: {{q_icon_color}};
font-size: 24px;
margin-right: 15px;
font-weight: 700;
}
.chevron {
margin-left: auto;
width: 20px;
height: 20px;
position: relative;
transition: transform 0.3s ease;
}
.chevron::before,
.chevron::after {
content: "";
position: absolute;
background-color: #ccc;
transition: all 0.3s ease;
}
/* プラスアイコン(閉じてる時) */
.chevron::before {
width: 2px;
height: 12px;
left: 9px;
top: 4px;
}
.chevron::after {
width: 12px;
height: 2px;
left: 4px;
top: 9px;
}
/* 回答部分 */
.faq-answer {
max-height: 0;
overflow: hidden;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.answer-inner {
padding: 0 30px 24px 30px;
display: flex;
align-items: flex-start;
}
.a-icon {
color: {{a_icon_color}};
font-size: 24px;
font-weight: 700;
margin-right: 15px;
flex-shrink: 0;
line-height: 1.2;
}
.faq-answer p {
margin: 0;
font-size: 15px;
line-height: 1.8;
color: {{text_color}};
opacity: 0.8;
}
/* 展開時の挙動 */
.faq-toggle:checked ~ .faq-question .chevron {
transform: rotate(45deg);
}
.faq-toggle:checked ~ .faq-question .chevron::before,
.faq-toggle:checked ~ .faq-question .chevron::after {
background-color: {{q_icon_color}};
}
.faq-toggle:checked ~ .faq-answer {
max-height: 500px;
padding-top: 10px;
}
/* モバイル対応 */
@media (max-width: 768px) {
.faq-question {
padding: 20px;
font-size: 15px;
}
.q-icon,
.a-icon {
font-size: 20px;
margin-right: 10px;
}
.answer-inner {
padding: 0 20px 20px 20px;
}
.faq-answer p {
font-size: 14px;
}
}
機能・使い方
- 「よくある質問(FAQ)」用のアコーディオンUIを生成するCSSデザインジェネレーターです。
- HTMLのチェックボックストグルを利用しているため、JavaScriptなしで動作します。
- Q/Aアイコンの色や、全体の背景色、文字色を自由にカスタマイズ可能です。
- デフォルトで「開いた状態」にするか、「閉じた状態」にするかを選択できます。
ポイント
max-heightを利用したアニメーションにより、スムーズな開閉動作を実現しています。
{{is_checked}}変数を利用して、生成されるHTMLの初期状態を切り替えています。