Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Mobile-first solution using Flexbox

tbrownlee 350

@tbrownlee

Desktop design screenshot for the FAQ accordion card coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Instead of simply changing display:none to display: block to reveal the answer, how would I reveal the question slowly?

Community feedback

@faruking

Posted

I would have told you to use the animation feature of CSS but you can't animate the display and height property of CSS. There are however other ways to achieve the desired result. Let's use plain Javascript code. Add the code below to your javascript file(inside the toggle(i) function after the second line).

let id = null;
  let pos = 0;
  clearInterval(id);
  id = setInterval(frame, 10);
  function frame() {
    if (pos == 50) {
      clearInterval(id);
    } else {
      pos++; 
      description[i].style.height = pos + "px"; 
    }
  }

Link to explanation Source

Marked as helpful

1

tbrownlee 350

@tbrownlee

Posted

@faruking Ah I see, thank you! That makes sense.

If I were to go the animation route, what element/s would I animate and how so?

0

@faruking

Posted

@tbrownlee The property you are going to animate is the max-height. Initially set the height of the element you want to animate to 0, then you gradually increase the max-height of the element to whatever you desire. Add this to your CSS code.

@keyframes mymove {
  from {max-height: 0px;}
  to {max-height: 600px;}
}

and add this at the end of your description class animation: mymove 5s 1 ;

Marked as helpful

1
tbrownlee 350

@tbrownlee

Posted

@faruking it works great!! Thank you for your advice!

0

@faruking

Posted

@tbrownlee You are welcome. Looking forward to more of your works.

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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