FAQ accordion main using HTML, CSS, and a bit of JavaScript.
Design comparison
Solution retrospective
I hope you like this solution, and I would appreciate your comments with observations and constructive criticism to continue improving my code.
Community feedback
- @danielmrz-devPosted about 1 year ago
Hello @ozkrTr!
Your project looks great!
I noticed that if you click on a question that's showing its answer, it doesn't close until you click on another question.
I had the same problem but mine worked with this js function:
function mostrar(pergunta, check, source, height) { if (checkbox[check].checked) { imagens[pergunta].src = source; answers[pergunta].style.height = height; } else { imagens[pergunta].src = 'assets/images/icon-plus.svg'; answers[pergunta].style.height = '0'; } }
What this funtion does is:
- If the question is closed, it opens when you click. And if your question is open, it closes when you click. But I didn't use
display: none
anddisplay: block
. I usedheight: 0
andheight: 90px
. It has the same effect, because if the height is 0, the answer does not appear.
I'm still a JavaScript student, but that worked really fine for me. If you want to take a look at my solution, here it is > link.
I hope it helps!
Other than this little detail, you did an excelent job!
Marked as helpful0@ozkrTrPosted about 1 year agothank you @danielmrz-dev for your comment, I took the opportunity to reassess the functionality through JavaScript. I reviewed your solution, and I found it very creative. I liked the animation in your project; unfortunately, I couldn't animate it because I used <details> to meet the requirement of navigating the questions and hiding/showing answers using keyboard navigation alone. However, I was able to correct the code to implement your suggestion.
1 - If the question is closed, it opens when you click. And if your question is open, it closes when you click. But I didn't use
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord