HTML
<ul class="faq__list">
<?php if (have_rows('faq_list')) : ?>
<?php while (have_rows('faq_list')) : the_row(); ?>
<li class="faq__item">
<p class="_q"><?php the_sub_field('faq_q'); ?><span class="plus"></span></p>
<p class="_a"><?php the_sub_field('faq_a'); ?></p>
</li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
JS
<script>
(() => {
const menu = document.querySelectorAll("._q");
function toggle() {
const content = this.nextElementSibling;
const icon = this.firstElementChild;
this.classList.toggle("active");
icon.classList.toggle("active");
content.classList.toggle("open");
if (content.classList.contains("open")) {
content.style.height = content.scrollHeight + 'px';
content.style.marginBottom = '1em';
} else {
content.style.height = "0";
content.style.marginBottom = '0';
}
}
for (let i = 0; i < menu.length; i++) {
menu[i].addEventListener("click", toggle);
}
})();
</script>
SCSS
.faq__item {
position: relative;
@include margin-bottom(10);
._q,
._a {
@include padding-left(35);
font-size: 1.6rem;
position: relative;
&::before {
@include font-size(18);
font-weight: 700;
color: var(--yellow);
position: absolute;
@include top_px(-4);
@include left_px(6);
}
.txt {
margin-bottom: 0;
}
}
._q {
font-weight: 500;
padding-bottom: 10px;
&::before {
content: "Q";
}
&::after {
content: "";
width: 100%;
height: 5px;
position: absolute;
bottom: 0;
left: 0;
@include bg-img("border-yellow", repeat-x, 80px);
}
&:hover {
opacity: 0.7;
cursor: pointer;
}
.plus {
display: block;
vertical-align: 0.3em;
color: var(--yellow);
line-height: 1;
width: 1em;
height: 3px;
background: currentColor;
border-radius: 0.1em;
position: absolute;
@include top_px(15);
@include right_px(15);
&::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: inherit;
border-radius: inherit;
transform: rotate(90deg);
transition-duration: 0.3s;
}
&.active:before {
transform: rotate(0deg);
}
}
}
._a {
height: 0;
overflow: hidden;
transition: all 0.5s;
margin-bottom: 0;
&::before {
content: "A";
color: var(--main);
}
}
}