FAQ accordion with HTML, CSS, Javascript
Design comparison
Solution retrospective
I did it, but i would like if someone help me, because if i open more than 1 option the text overextend the card itself, and i think that if i could create a function that make just one option avaiable to open at time, but i dont know how to do it, can someone helps me with it?
Community feedback
- @beniusisPosted 10 months ago
Hey 👋 Congratulations on completing the challenge!
The text overflows because you have set the card's height as 34rem. To fix that, you can set
height: fit-content
.1 - @GudelisPosted 10 months ago
Hi,
Just did this project also, you can check my solution to have one question open at a time. https://www.frontendmentor.io/solutions/faq-accordion-psETbWsVvf
Shortly, I created function to check if clicked question is equal to already opened question, if not it, hides it and shows new one.
0 - @MariaValentinovaPosted 10 months ago
Hi, there! I personally took advantage of all the default functionalities of Bootstrap to create the accordion and control its behavior. You can look at my code in case it is helpful to you. You can achieve closing the previously opened item when opening a new one by keeping track of the currently opened item and closing it before opening the new one. Here are some suggestions to implement this in your code: 1.Create a global variable to track the currently opened item. You can initialize it with null initially since no item is open at the beginning. Like: let currentItem = null; 2.Modify the showhide and hideshow functions: When opening an item, check if there is currently an open item (currentItem is not null). If there is one, close it before opening the new item. When closing an item, update the currentItem variable to null.
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