
Accordion - Accessibility
Design comparison
Solution retrospective
I could not get the description paragraphs to transition instead of just pop open. I'm looking for advice if someone wants to look at my code. Look at src/sass/style.scss and scroll down to "// FEM Community:"
Community feedback
- P@FacundoDLRPosted about 1 month ago
mmm well I still don't understand all your code, I think you used react for your project and I haven't started with that framework yet, but according to the css I see I can suggest you look at the
background-size
property you used in body, it doesn't respond very well on mobile devices, an alternative you can use to create the two-color background is by using a container that has the approximate measurements for the purple color along with the background svg pattern.On the other hand, if what you are looking for is to create a kind of transition when each list is clicked and it expands creating a smooth slide, you can try with css and js. For that we will use the
max-height
properties in combination withoverflow:hidden
andtransition
but first you should check (remove) thehidden
attribute in each <p> element. Example:li p { max-height: 0; overflow: hidden; opacity: 0; transition: max-height 0.4s ease-in-out, opacity 0.4s ease-in-out; } li button[aria-expanded="true"] + p { max-height: 200px; /* Adjusts according to content */ opacity: 1; }
Now with the help of js we will use the attribute
aria-expanded
to switch between true/false. First we select all the buttons and then we add a click event to each one to togglearia-expanded
and that's it, it should work.const allButtons = document.querySelectorAll("button"); allButtons.forEach((button) => { button.addEventListener("click", () => { const expanded = button.getAttribute("aria-expanded") === "true"; button.setAttribute("aria-expanded", !expanded); }); });
I hope it helps you in some way, Greetings!
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