FAQ Accordion Card with HTML, CSS and Vanilla JS
Design comparison
Solution retrospective
This component was designed for desktop and mobile only, if you display on tablet, it's not gonna looks so good. Need to fix some issues for the hover effect on touch screens with more than 375px size.
Please, if you see something wrong or there's another way to do it better, tell me as soon as possible.
Community feedback
- @isprutfromuaPosted over 2 years ago
Hi there. You did a good job 😎
keep improving your programming skills🛠️
your solution looks great, however, if you want to improve it, you can follow these steps:
✅instead of this loop, you can hide all these items at once
//first loop to set property display = none to all faqs answers (<p>) for(faqs of faq) { faqs.style.display = 'none'; }
✅instead of setting inline styles, it is better to set classes
if(faq[i].style.display == 'none') { faq[i].style.display = 'block'; arr[i].style.fontWeight = 'bold'; icon[i].style.transform = 'rotate(0.5turn)'; } else { faq[i].style.display = 'none'; arr[i].style.fontWeight = 'normal'; icon[i].style.transform = 'rotate(1turn)'; //rotate the arrow icon when the user click on button }
I hope my feedback will be helpful. You can mark it as useful if so 👍
Good luck and fun coding 🤝⌨️
1@gfernan24373Posted over 2 years ago@isprutfromua Thanks again for your tips. In the css file I already set the display to none for the <p> tags but I don't know why this property and all the others are not inicialized when I using in the JS file. That's the reason why I reset the propertie value with the for loop. I'm gonna learn how to hide all these items at once and avoid using for loops.
llmmll,,
0
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